Allocation and Free in Micriμm μC/OS-III RTOS

心不动则不痛 提交于 2019-12-11 03:03:46

问题


We are using the μC/OS-III RTOS of Micrium with a RX62N of Renesas.

We built a system where we have to dynamicly alloc and free data. We found out the functions malloc() and free() are not working well with the RTOS. However the RTOS has a custom function for this; the Mem_HeapAlloc() function. This function allocates some memory of the RTOS' made 'heap'. Problem is that it does not have a free function, probably because everything goes into a heap pool.

In the RTOS it is also possible to make a pool. Problem of this pool is that all the containing blocks need to be the same size. Since we are allocating and freeing different sizes, this is not a good solution for us.

We found a document which describes the memory RTOS functions HERE Chapter 4 describes the functions.

Does somebody have any idea how we could fix this problem ?

Some solutions we allready had

  • Make all the blocks sizes the same as the biggest allocation. We have a lot of overhead since the smallest and biggest allocation differ a lot.
  • Don't do a free. This is no solution, there will be a memory leak.

Hope somebody can help us. If something is not clear, please ask me

Thanks in advance


回答1:


  • you can allocate your objects in multiples of block sizes.

You would still have some internal fragmentation due to which you will not be able to fully utilize available space.

You would still have following advantages using memory pools

  • Memory pools allow memory allocation with constant execution time (no fragmentation). The memory release for thousands of objects in a pool is just one operation, not one by one if malloc is used to allocate memory for each object.

  • Memory pools can be grouped in hierarchical tree structures, which is suitable for special programming structures like loops and recursions.

  • Fixed-size block memory pools do not need to store allocation metadata for each allocation, describing characteristics like the size of the allocated block. Particularly for small allocations, this provides a substantial space savings.



来源:https://stackoverflow.com/questions/10717409/allocation-and-free-in-micri%ce%bcm-%ce%bcc-os-iii-rtos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!