Heap free size: multi_heap_free_size vs esp_get_free_heap_size

yaghmr
Posts: 9
Joined: Fri Dec 09, 2022 4:00 pm

Heap free size: multi_heap_free_size vs esp_get_free_heap_size

Postby yaghmr » Thu Nov 09, 2023 9:53 am

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

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Heap free size: multi_heap_free_size vs esp_get_free_heap_size

Postby MicroController » Thu Nov 09, 2023 11:55 am

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.

yaghmr
Posts: 9
Joined: Fri Dec 09, 2022 4:00 pm

Re: Heap free size: multi_heap_free_size vs esp_get_free_heap_size

Postby yaghmr » Thu Nov 09, 2023 1:04 pm

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 );
}

Who is online

Users browsing this forum: No registered users and 314 guests