zig icon indicating copy to clipboard operation
zig copied to clipboard

Adds std.heap.MemoryPool

Open ikskuh opened this issue 3 years ago • 1 comments

This is a fast memory pool implementation that can be used to rapidly allocate objects of the same type. It even outperforms the null hypothesis of just leaking the memory using a std.heap.ArenaAllocator.

ikskuh avatar Aug 23 '22 09:08 ikskuh

nice!

Jarred-Sumner avatar Aug 31 '22 00:08 Jarred-Sumner

TODO: Potentially store all allocated objects in a list as well, allowing to just move them into the free list instead of actually releasing the memory.

Unless there's some drawback I'm not seeing, including a list of allocated items would also be nice for general storage/iteration purposes since one of the benefits you get from an arena is cache locality, and there's a decent chance that if you're using a pool for a particular type that you're also going to want to access those items sequentially rather than randomly, so having that storage would remove an extra step for the user.

If there would be drawbacks to doing this (I suppose ensuring everything is kept in order might be tricky?) then perhaps a secondary StoredMemoryPool type might also be a good idea.

BanchouBoo avatar Dec 29 '22 16:12 BanchouBoo