r/cprogramming • • Mar 20 '26
Memory allocator from scratch in C, would appreciate feedback
been learning C and decided to try building my own malloc/free. its pretty basic but it works i think. has block splitting, coalescing, leak detection, and i added canary values to catch buffer overflows.
windows only since it uses VirtualAlloc.
https://github.com/1s7g/jank-malloc
first time doing something like this so probably did some stuff wrong. any feedback appreciated, especially on the coalescing logic and the pointer math. not sure if i did alignment correctly either.
7
Upvotes
7
u/zhivago Mar 20 '26
At a glance, it doesn't handle alignment properly.
5
u/flyingron Mar 20 '26
Do not use symbols starting with underscore at file scope. These are reserved for the implementation.
1
u/yuehuang Mar 22 '26
Good job. Now profile it. You will learn a lot about performance too.
2
u/[deleted] Mar 22 '26
[removed] — view removed comment