Handmade Hero»Forums»Code
9 posts
None
General Purpose Allocator and MergeIfPossible
Hey,

i think in your implementation of MergeIfPossible you're missing to merge with all free chunks of memory. Let's say you have a Chunk A (which is free), B (in use), and C (free). After freeing B you'll merge B with C, but miss the oportunity to merge with A.

Unless i'm missing something obvious.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
General Purpose Allocator and MergeIfPossible
Please look at the call site for MergeIfPossible and note that it is called twice, once for B-C (in your example) and once for A-B. If you still think there is a problem, please let me know what it is and I'll take a look!

- Casey
9 posts
None
General Purpose Allocator and MergeIfPossible
Yep, right you are. Sorry for the noise.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
General Purpose Allocator and MergeIfPossible
No problem at all - it is always better to be safe than sorry!

- Casey