- Add alignment macro definitions (
ALIGN,ALIGN_UP) - Implement alignment in
_malloc(round up allocation sizes) - Test alignment with unaligned requests (e.g., 5 bytes)
- Verify all returned pointers are 8-byte aligned
-
Implement
_calloc(size_t nmemb, size_t size)- Add overflow check
- Allocate memory using
_malloc - Zero-initialize with
memset - Test with array allocation
-
Implement
_realloc(void *ptr, size_t new_size)- Handle NULL pointer (redirect to malloc)
- Handle zero size (free and return NULL)
- Validate pointer with magic number
- Check if current block is large enough
- If not, allocate new block, copy data, free old
- Test growing and shrinking allocations
- [] Implement
expand_heap()function- Request new page via
mmap - Initialize new block header
- Find last block in current heap
- Link new page to existing heap
- Update prev/next pointers
- Request new page via
- Modify
_mallocto callexpand_heap()when out of memory - Test allocating more than 4KB total
- Verify multiple pages are linked correctly
-
Create comprehensive test suite
- Test alignment edge cases
- Test calloc zeros memory correctly
- Test realloc preserves data
- Test multi-page allocation
- Test allocating hundreds of small blocks
- Test fragmenting and coalescing repeatedly
-
Add heap consistency checker (walk list, verify all pointers)
-
Test buffer overflow detection (if you add red zones)
-
have another free_list with only freeblocks
-
Add actual benchmarks - Compare malloc/free speed against glibc for 10M ops
-
Measure fragmentation - Track (total_allocated / total_pages) over time
-
Fix realloc - Actually implement shrinking properly
-
Add thread safety - Even a single mutex would be better than nothing
- Add global recursive mutex
- Lock/Unlock in public APIs
- Verify with
test_threads
- Implement size classes (Segregated Free Lists)
- Create array of free lists for small sizes (16, 32, 64, 128, 256, 512, 1024)
- Update
_mallocto pick from specific bucket - Update
_freeto return to specific bucket - Benchmark impact
- Return pages to OS
- Identify when a full page is free
- Use
munmapto release memory - Verify using system tools (e.g.
htoporps)
- Remove all TODO comments
- Add function documentation comments
- Clean up debug print statements
- Write README explaining your allocator
- Document known limitations
- Add heap statistics tracking (bytes allocated, peak usage, fragmentation)
- Implement large allocation optimization (direct mmap for >128KB)
- Add red zones for buffer overflow detection
- Create visualization tool to show heap state