systems · sub-star
custom_mem_alloc
thread-safe memory allocator talking straight to the OS via mmap.
readme
A replacement for malloc written in C that interfaces directly with the operating system. It requests one large contiguous region of virtual memory up front through mmap, then slices that region for the program itself with minimal overhead, managing its own free list, aligning every allocation, and staying safe under threads.
artifact
simulated heap: mallocs claim blocks, frees release them, the pool gets recycled.
signal log
- mmap-backed: grabs one contiguous 1 MB region from the OS and serves every later request out of it.
- first fit with splitting, and coalescing with only the adjacent blocks: since free neighbours never coexist, a free need not sweep the whole list, which made it 1.3 to 1.5 times faster.
- misuse aborts instead of corrupting: a double free, a pointer from outside the arena, or a pointer into the middle of a block. requests are bounded before alignment rounding, where malloc(SIZE_MAX) used to wrap to a live pointer.
- thread-safe via one mutex, tested with eight threads of verified churn.
- benchmarked honestly against glibc: 2 to 6 times slower, because first fit walks every block where glibc indexes by size.
built with
Cpthreads