Memory pooling

This forum is for general developer support questions.
Post Reply
User avatar
trixie
Posts: 411
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Memory pooling

Post 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.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
LyleHaze
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 525
Joined: Sat Jun 18, 2011 5:06 pm
Location: North Florida, near the Big Bend

Re: Memory pooling

Post 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.
User avatar
Hans
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 703
Joined: Tue Dec 21, 2010 9:25 pm
Location: New Zealand
Contact:

Re: Memory pooling

Post 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
http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more. Home of the RadeonHD driver for Amiga OS 4.x project.
User avatar
trixie
Posts: 411
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic

Re: Memory pooling

Post by trixie »

Thank you both!
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
Post Reply