This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

when do i need (have to) to use nrf memory manager and when i can use malloc\calloc\free

Hi.

I'm using nrf52840 SDK 16 with S140.

in my last piece of code static arrays were not enough and i needed malloc.

I used malloc without any issue, also i use cJSON and it uses malloc as well. again with no issue as far as i can see.
However my CTO used our prohject with small modification to work with free_rtos and had hardfaults, apparently after changing to memory manager with nrf_malloc\nrf_free his hardfaults were over.

This brings me to the question when should i use memory manager, why should i use it at all (is it that better in preventing fragmentation) ?

Also considering that i want to use dynamic memory to save on ram space (i don't want to define static array size of X (where each element is sizeof(my_struct)) when i can dynamically allocate an array size of y where y < x is it worth the risk in most cases ? (yeah i know this is more philosophical than an actual deterministic question)

Parents
  • nRF memory manager was designed to have a memory pool manager for the baremetal solutions which does not have the fancy memory libraries that are in RTOS or any other imported libraries. the malloc available in FreeRTOS should have been enough for you. I am uncertain about the fragmentation benefits of using the nRF memory manager as we have not done side by side benchmarks on this and the one with FreeRTOS.

    I would have tried to understand the hardfaults and its contexts before trying to have a overall conclusion on what is better. FreeRTOS have many different heap variations that can be used to best suit the application and i would have strongly thought that these variations would be enough and efficient when using freertos as compared to nRF memory manager.

Reply
  • nRF memory manager was designed to have a memory pool manager for the baremetal solutions which does not have the fancy memory libraries that are in RTOS or any other imported libraries. the malloc available in FreeRTOS should have been enough for you. I am uncertain about the fragmentation benefits of using the nRF memory manager as we have not done side by side benchmarks on this and the one with FreeRTOS.

    I would have tried to understand the hardfaults and its contexts before trying to have a overall conclusion on what is better. FreeRTOS have many different heap variations that can be used to best suit the application and i would have strongly thought that these variations would be enough and efficient when using freertos as compared to nRF memory manager.

Children
No Data
Related