https://github.com/amrdb/babymalloc
A dynamic memory allocator library in C
https://github.com/amrdb/babymalloc
Last synced: 11 months ago
JSON representation
A dynamic memory allocator library in C
- Host: GitHub
- URL: https://github.com/amrdb/babymalloc
- Owner: amrdb
- License: mit
- Created: 2024-08-16T13:37:33.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-18T10:49:40.000Z (over 1 year ago)
- Last Synced: 2025-04-21T09:52:12.941Z (about 1 year ago)
- Language: C
- Homepage:
- Size: 38.1 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# babymalloc
A dynamic memory allocator in C, inspired by the [CS:APP malloc lab](http://csapp.cs.cmu.edu/3e/labs.html) from the CMU course [Intro to Computer Systems](https://www.cs.cmu.edu/afs/cs/academic/class/15213-f15/www/schedule.html).
### Description
This is a dynamic memory allocator that utilizes simple techniques:
- First-fit placement policy:
- The allocator searches for the first free block that is large enough to fit the requested size.
- Boundary tags:
- Each block contains a header and footer that store the size of the block and whether the block is allocated or free.
- This allows the allocator to traverse the heap in both directions.
- Implicit free list:
- The allocator uses a simple implicit free list to keep track of free blocks.
- The allocator traverses the free list using the size of the blocks.
- Immediate coalescing:
- When a block is freed, the allocator checks if the adjacent blocks (in both sides) are free and coalesces them.
- Splitting:
- When a free block is selected for an allocation, the allocator checks if the block is large enough to be split into two blocks.
- sbrk:
- The allocator uses the sbrk system call to request more memory from the kernel when the heap is full.
- Alignment:
- The allocator aligns the blocks to the word size of the CPU.
- Platform Compatibility:
- The allocator works on 64-bit, 32-bit and smaller CPUs on UNIX-like systems.