Page 1 of 1
Memory pooling
Posted: Mon Jul 30, 2012 5:24 pm
by trixie
My program does a lot of on-the-fly memory allocations: small amounts of memory (< 128 bytes) constantly get allocated and freed. I was wondering if using a memory pool would be more considerate of the memory system, especially as regards fragmentation.
Re: Memory pooling
Posted: Mon Jul 30, 2012 7:14 pm
by LyleHaze
Yes.
It also provides a simple way to free the entire pool if desired.
If your "small amounts of memory" are all the same size, you might also consider an ItemPool (ASOT_ITEMPOOL) instead of MemoryPool(ASOT_MEMPOOL), which can optimize for many same-sized allocations.
Re: Memory pooling
Posted: Tue Jul 31, 2012 12:20 am
by Hans
trixie wrote:My program does a lot of on-the-fly memory allocations: small amounts of memory (< 128 bytes) constantly get allocated and freed. I was wondering if using a memory pool would be more considerate of the memory system, especially as regards fragmentation.
Are these items all of the same size? If so, please use item pools instead. They're designed especially for the frequent allocation and deallocation of small blocks that are all the same size.
Look up ASOT_ITEMPOOL, ItemPoolAlloc()/ItemPoolFree() in the Exec autodocs.
Hans
Re: Memory pooling
Posted: Tue Jul 31, 2012 2:11 pm
by trixie
Thank you both!