handmade.network » Forums » Question on Casey's memory allocation implementation
boagz57
Jason
113 posts
#21016 Question on Casey's memory allocation implementation
4 months, 1 week ago Edited by Jason on May 9, 2019, 4:43 p.m. Reason: Initial post

As far as I understand, Casey originally had his memory allocation setup so that he could just separate the allocated memory block into separate 'memory arenas'. So you could have a memory arena allocated for all world objects you'll create, an arena for all assets, an arena for a render buffer, etc. But later on he added the possibility of a 'sub-arena' to sub allocate an arena even further. I was wondering what the purpose of the sub-arena's were and if they are really necessary? I ask this because I was thinking of creating a memory scheme based off his but I figured it would look something like:

1
2
3
4
5
6
i32 generalHeap_id = CreateParitionFromMemoryBlock(gameMemoryBlock, Megabytes(100), DYNAMIC); 
i32 assets_id = CreateParitionFromMemoryBlock(gameMemoryBlock, Megabytes(200), FRAME); 
i32 renderBuffer_id = CreateParitionFromMemoryBlock(gameMemoryBlock, Megabytes(10), LINEAR); 

i32* thing = Alloc(gernalHeap_id, i32, 1);
Render_Command* command = Alloc(renderBuffer_id, Render_Command_Type, 1);

.......

Basically I would be partitioning off memory arena's and specifying what type of allocation scheme I want to run on each of them when allocating memory. I thought this would handle most situations but I'm wondering what I might be missing and if I need to add in the possibility to sub-allocate an arena even further?
mrmixer
Simon Anciaux
661 posts
#21018 Question on Casey's memory allocation implementation
4 months, 1 week ago

SubArena is just a simple way to reserve a block of memory. It's equivalent to your CreatePartitionFromMemoryBlock function (you wrote parition instead of partition, unless parition means something).
boagz57
Jason
113 posts
#21019 Question on Casey's memory allocation implementation
4 months, 1 week ago

Haha, na, I just misspelled partition. Okay, so it's really not much different from what I'm already doing. Thanks!