Skip to main content
RDodd.1
Associate
Feb 8, 2023 11:19 PM UTC
Question

osMemoryPoolDelete or osMemoryPoolFree ?

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

This topic has been closed for replies.

4 replies

KnarfB
Super User
Feb 9, 2023 5:40 PM UTC

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
RDodd.1Author
Associate
Feb 9, 2023 6:29 PM UTC

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?

KnarfB
Super User
Feb 10, 2023 8:50 AM UTC

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
Principal III
Feb 19, 2023 10:18 PM UTC

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