5 ms·
A custom pool for objects is often a good idea. Pre-allocate “enough” memory and dish them out as appropriate, releasing back to the pool when the reference cou
by OnlyMortal 3y ago
A custom pool for objects is often a good idea. Pre-allocate “enough” memory and dish them out as appropriate, releasing back to the pool when the reference count goes to zero.
You can also use the pool to bound the maximum size you’re able to allow.
- mathiasgredal 3y agoWhy is this better than an arena style allocator?
- akoboldfrying 3y agoIt is an arena-style allocator. At least, if someone asked me to explain what an arena allocator is/does, I would say essentially what they wrote -- likely without the "disappears automatically once all references disappear" part, which is IMHO just a clever nice-to-have.
- OnlyMortal 3y agoYou allocate a large lump of memory up front and supply parts of it on demand. This would be different from an allocator which may allocate smaller amounts of memory as needed. This can help reduce memory fragmentation. It also helps to bound your memory usage. A request could block until memory was free.
- winrid 3y agoMan, if only something already did this. We could call it Oak... Or maybe Java? :)