A malloc and free replacement written in C. Manages a fixed arena, tracks free
chunks in a linked list, and hands out and reclaims memory without the standard
library.
mem_alloc(size)finds a chunk, splits it, and returns a pointer past the headermem_free(ptr)walks back to the header, returns the chunk, and coalesces neighborsinit(size)/destroy()set up and tear down the arena
set_allocation_strategy switches how find_free_chunk picks a chunk, which changes
the fragmentation profile of the same workload:
- First fit takes the first chunk large enough, fastest to search
- Best fit takes the smallest sufficient chunk, minimizes wasted bytes per allocation
- Worst fit takes the largest, leaving bigger remainders behind
set_free_list_order independently controls whether the free list is kept in address
order or size order.
split_node carves a request out of a larger chunk and leaves the remainder on the
list, but only when the remainder is big enough to hold a header. coalesce_nodes
merges adjacent free chunks on release, which is what keeps the arena from degrading
into unusable slivers over a long run of allocations and frees.
get_header does the pointer arithmetic to recover a chunk's metadata from the user
pointer, which is the same trick real allocators use.
Written in C for CST 334 Operating Systems at CSU Monterey Bay.
makeThis repository contains the implementation only. The course's unit test harness and autograder configuration are instructor materials and are not included, so the build here will not run the graded test suite.