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

What is the difference of malloc and nrf_malloc?

I'm working with nrf51822.

  • Hello Filipe

    The nrf_malloc() function call is part of the memory manager module, and is more or less a wrapper for the nrf_mem_reserve() function call. The memory manager module uses fixed memory block sizes when allocating memory to prevent fragmentation. nrf_mem_reserve() first ensures that the requested size is valid, before finding a free memory block of appropriate size to allocate. Normally this function would return two parameters, a pointer to the allocated memory, and the actual size of allocated memory. With nrf_malloc you only receive the location pointer, so it behaves more like malloc(), while still employing the fixed memory block sizes of the memory manager module.

    For more information on the memory manager module see Nordic’s infocenter:

    infocenter.nordicsemi.com/.../lib_mem_manager.html

    Best regards

    Jørn Frøysa

Related