3 ms·
"Each chunk of memory has a node struct at the begining and a footer struct at the end." As a public service announcement, if you are building a heap manager f
by ChuckMcM 9y ago
"Each chunk of memory has a node struct at the begining and a footer struct at the end."
As a public service announcement, if you are building a heap manager for C code, don't do this (put your heap control structures next to the allocated memory). Sure it looks elegant, however a VERY common C bug is the 'off by one' error, and when an off-by-one can corrupt the structures that define the heap, well it gets out of hand quickly.
Have your heap structures "far" away from the allocated memory. Yes you burn another N bits (where N is log2(max_address)) in your heap control structures, and yes you may have heap control structures you "don't need" pre-allocated, but your future self will thank you for doing it this way.