Page 1 of 1

CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC vs CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC

Posted: Mon Feb 12, 2024 3:42 pm
by glrtheil
What is the difference between CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC and CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC? This doesn't seem to be explained anywhere.

Re: CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC vs CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC

Posted: Wed Feb 14, 2024 1:45 pm
by MicroController
The help text in menuconfig for "Memory allocation strategy" describes the strategies:

"Internal DRAM memory only" vs. "Either internal or external memory based on default malloc() behavior in ESP-IDF"

Re: CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC vs CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC

Posted: Thu Feb 22, 2024 5:32 pm
by glrtheil
MicroController wrote:
Wed Feb 14, 2024 1:45 pm
The help text in menuconfig for "Memory allocation strategy" describes the strategies:

"Internal DRAM memory only" vs. "Either internal or external memory based on default malloc() behavior in ESP-IDF"
Unfortunately, Espressif has broken the help text for menuconfig in vscode plugin, so that information is unavailable to me. That said, even that description tells us nothing. It doesn't explain why internal is actually the default, and what the behavior is in default mode. It's been said elsewhere that default results in static memory allocation, but I'm unable to substantiate that claim.

Re: CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC vs CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC

Posted: Thu Feb 22, 2024 8:12 pm
by MicroController
It doesn't explain why internal is actually the default, and what the behavior is in default mode.
True. To understand what the options actually mean you have to know about the 'capabilities-based' heap allocator and that you can globally configure malloc's behavior in the IDF: https://docs.espressif.com/projects/esp ... via-malloc

TL;DR: Code (like mbedtls) can explicitly force allocations to internal (or external) RAM by using the capabilities-based allocator API; or the code can just use standard malloc() which may allocate in internal or external RAM depending on how the global CONFIG_SPIRAM_USE is set.