Page 1 of 1

Heap free size: multi_heap_free_size vs esp_get_free_heap_size

Posted: Thu Nov 09, 2023 9:53 am
by yaghmr
What is the difference between multi_heap_free_size() and esp_get_free_heap_size()?

The documentation for the former says: 'Returns free heap size. Returns the number of bytes available in the heap.' For the latter: 'Returns the current size of free heap memory'.

Re: Heap free size: multi_heap_free_size vs esp_get_free_heap_size

Posted: Thu Nov 09, 2023 11:55 am
by MicroController
multi_heap_free_size(...) is the lower-level function for querying one specific heap, identified via its handle. Normally, you don't manage heaps yourself and thus have no use for this function - and no heap handle for it in the first place.
As it says in the documentation:
(Note: The multi-heap API is used internally by the heap capabilities allocator. Most ESP-IDF programs never need to call this API directly.)
esp_get_free_heap_size() is higher-level and returns the sum of free space over all heaps known to the multi-heap allocator.

Re: Heap free size: multi_heap_free_size vs esp_get_free_heap_size

Posted: Thu Nov 09, 2023 1:04 pm
by yaghmr
MicroController wrote:
Thu Nov 09, 2023 11:55 am
multi_heap_free_size(...) is the lower-level function ...
Thanks for the clarification. I understand, just like esp_get_free_heap_size() is equals to heap_caps_get_free_size((MALLOC_CAP_DEFAULT))?

Another question, is the heap_caps_print_heap_info() function also intended for internal use or simply for providing more detailed information than esp_get_free_heap_size()?

EDIT:
I found these lines in the source code:

Code: Select all

uint32_t esp_get_free_heap_size( void )
{
    return heap_caps_get_free_size( MALLOC_CAP_DEFAULT );
}

uint32_t esp_get_free_internal_heap_size( void )
{
    return heap_caps_get_free_size( MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL );
}