Hi,
Ok, during summer months here in the Northern Hemisphere, my coding efforts are pretty darn low. However, every now and then I come up with some little things (issues) that I think need to be sorted out.
For about all of my projects I make use of a mempool, as I once came to the conclusion, that that was a good idea, mainly because it allows to integrally set the allocated area to 0x00 all over upon successfull allocation. This effectively means that in an allocated structure Booleans are set to FALSE, numbers to 0 and char arrays to 'terminated'. This part sets up the mempool:
void *MemPool = IExec->AllocSysObjectTags(ASOT_MEMPOOL, ASOPOOL_MFlags , MEMF_CLEAR | MEMF_VIRTUAL , ASOPOOL_Puddle , 4096 , ASOPOOL_Threshold, 1024 , TAG_END);
Can this be improved for efficiency?
What is the effect of the 'Treshold'-tag? What exactly does that do?
OldFart
I haven't had occasion to use memory pools myself, but the OS4 Wiki has a section on them and how they work, including what the threshold value does and how to adjust it: https://wiki.amigaos.net/wiki/Exec_Memory_Pools
@OldFart
When it comes to memory allocation efficiency, the first question you need to ask yourself is: "Am I going to allocate and free memory repeatedly?" If no, then you don't need pools, and standard mem allocations using AllocVecTags() will do for you.
The second question is: "Am I going to always allocate the same size, or different sizes?" If allocating the same size, use an item pool instead, the allocations will be faster.
Other than that, I'd point out that you shouldn't use the MEMF_VIRTUAL flag. Use MEMF_PRIVATE, or MEMF_SHARED if the memory is going to be shared between different tasks.
AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2
@all
The first and formost reason I switched to using a mempool, was the reduction of memory fragmentation, the abillity to allocate 'clean' (= set to 0) memory and, due to the 'tracking' nature of the mempool, the reduced risk of memory leakage due to memory not being freed explicitly at closing time. The mempool takes care of that, as far as I can read from the documentation.
After the mempool has been established, first thing after starting the program, I make use of one of the following macro's for allocation
and of course a macro for freeing:
Might my insight on the matter change, a simple replacement of these macro's would be enough, beit definitive or just one time.
Thanks for all your input. Much appreciated!
OldFart
If an allocation is lower or equal to the threshold value then AllocPooled() and there is no existing puddle that can satisfy the request then it will allocate a new puddle of the specified puddle size and leave any extra memory to potentially be used by future AllocPooled() calls.
If the allocation exceeds the threshold value then AllocPooled will allocate exactly the amount of memory that is requested and not a byte more.
Basically you want to set the threshold to just large enough that when you subtract it from the puddle size it will leave just enough free memory to still be useful.
The main benefit of the puddles is that if the allocation request can be satisfied by an existing puddle it will be faster because it won't have to request new memory from the free store. If you only do allocations rarely and only use the memory pool to keep track of allocations you might want to set puddle and threshold sizes to zero so that it always allocates only as much memory as needed.