2023-02-08 03:19 PM
Hi,
I have allocated memory pool for my doubly linked list using
osMemoryPoolNew
I want to be able to insert and delete nodes to the doubly linked list. My question is , When I am deleting the node I am unsure if I have to using osMemoryPoolDelete or osMemoryPoolFree.
I know I should be using FREERTOS vPortFree . But I am unsure in CMSIS context. Can anyone please clarify this .
Thanks
2023-02-09 09:40 AM
osMemoryPoolNew and osMemoryPoolDelete is one function pair for an entire pool, and
osMemoryPoolAlloc and osMemoryPoolFree a pair for a memory block within a pool, like your nodes.
See https://arm-software.github.io/CMSIS_5/RTOS2/html/group__CMSIS__RTOS__PoolMgmt.html
Keep in mind, that there is no virtual addressing available, so heavy dynamic use of alloc and free may defragment the heap or, at least, have non-constant run-time.
hth
KnarfB
2023-02-09 10:29 AM
Thank you ! I have couple of follow up questions
So do I have to create a pool before I use osMemoryPoolAlloc and osMemoryPoolFree?
I am using heap_4.c . Do you think there will be still defragmentation problem ? Or what is the other way you might suggest ? Do I have to just goahead with Arrays than doubly linked list?
2023-02-10 12:50 AM
It all depends on your usage pattern. osMemoryPoolAlloc doesn't call heap malloc.
Check the implementation of memory pools in cmsis_os2.c. Note how AllocBlock walks a linear list to find a free block.
Pools are typically used for equally sized (larger) buffers. Say, if you move buffers of digitized audio around in queues, you want to move them "copy-free", which can be achieved with memory pool buffers and only pointers in the queues.
hth
KnarfB
2023-02-19 02:18 PM
> heavy dynamic use of alloc and free may defragment the heap
The topic is about pools, not heaps, and pools cannot fragment.
> Do you think there will be still defragmentation problem ?
It's the fragmentation, not the opposite one.
> there is no virtual addressing available
By the way, virtual memory solves the fragmentation of physical memory, but still cannot solve the fragmentation of a virtual address space for a particular process.