Discussion about this post

User's avatar
Trần Thành Long's avatar

A couple of questions:

1. People usually make a scratch arena locals to a thread using something like __declspec(thread). What if you're on a platform or project that can't use thread-local storage? I usually see people handle this by passing around a "thread context" Care to comment on that?

2. The push and pop operator on the current arena implementation aren't atomic, which mean they aren't thread-safe. How do you go about dealing with memory management for multithreading?

3. Do you think the idea of ArenaTemp can be made more abstract and applied to other kinds of allocators? For example, I may have a generic heap allocator that keeps a free list and allows for out-of-order alloc and free allocations. I can still create an ArenaTemp for this allocator by storing the free list in the ArenaTempBegin and restoring it in the ArenaTempEnd function. The same also goes for a pool allocator, for example. I can still store the current free list and reset it later.

Expand full comment
Cristián Donoso's avatar

Hey Ryan,

Great article. I ended up going pretty much all in on memory arenas for an game/engine I'm working on. I've had some growing pains, but so far has been going great.

I do have some questions about "non-trivial" lifetime "groups", if you will.

Like I defined some arenas that are known: permanent, string, level, frame, scratchs. Those are all good and fine, but I've found stuff, like editor UI (think imgui stuff) to be a bit complicated since they seem to want to have their own lifetime. Think like strings to display on the imgui window, that are calculated from some other data.

I guess I could roll it into the "level" arena, but sometimes I feel windows want to be updated/recalculated in their own time. What I tried is static arenas that are defined explicitly for that window, that I clear when it's convenient. It can work, but I do find it a bit messy.

Like if I follow the trail of thought of your article, each "lifetime group" would have it's own arena (that maybe comes itself from another arena). I wonder how that works in practice for you, especially in terms of UI or other kinda "orthogonal" lifetime elements.

Expand full comment
36 more comments...

No posts