cancel
Showing results for 
Search instead for 
Did you mean: 

osMemoryPoolDelete or osMemoryPoolFree ?

RDodd.1
Associate II

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

4 REPLIES 4
KnarfB
Principal III

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

RDodd.1
Associate II

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?

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

Piranha
Chief II

> 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.