Handmade Hero » Forums » Code » question about FrameArena
Skinpop
Gus Waldo
10 posts
#16290 question about FrameArena
2 months ago Edited by Gus Waldo on Sept. 11, 2018, 1:58 a.m.

I was looking at the HH source for the first time in a while and noticed that FrameArena seems to be dynamically allocating and de-allocating (using platform calls to virtualalloc/free) all of its memory every frame. I thought one of the points of using big chunk allocations was to avoid that kind of overhead but with this implementation wouldn't the frame arena have to make a lot of platform allocations if a lot of memory is needed(which often is the case for frame memory)? What am I missing?
mrmixer
Simon Anciaux
477 posts
#16299 question about FrameArena
2 months ago

The frame arena only uses a few blocks of memory (6 allocations on my quick test). So it's not really an issue.
If at some point we saw that becoming an issue, we could allocate larger blocks (I believe the default size now is 1Mo per block) or keep the blocks in a free list or something like that. But most of the "persistent" memory (not the FrameArena) in HMH is allocated once and then kept until we close the program.
Skinpop
Gus Waldo
10 posts
#16302 question about FrameArena
2 months ago

that makes sense and I guess Casey will continue to tune the memory allocations. In my own code I initialize a persistent chunk for my frame-arena, but it still has the ability to automatically allocate and deallocate additional chunks on top of that if needed.