Skip to main content
Visitor II
February 8, 2023
Question

osMemoryPoolDelete or osMemoryPoolFree ?

  • February 8, 2023
  • 3 replies
  • 2102 views

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.

    3 replies

    Super User
    February 9, 2023

    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.1Author
    Visitor II
    February 9, 2023

    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?

    Super User
    February 10, 2023

    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

    Graduate II
    February 19, 2023

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