SPIRAM option CONFIG_SPIRAM_USE_MEMMAP

Alberk
Posts: 55
Joined: Sat Jun 19, 2021 1:49 am

SPIRAM option CONFIG_SPIRAM_USE_MEMMAP

Postby Alberk » Fri Jul 28, 2023 7:29 am

Hi,

Is there any documentation that explain the difference between CONFIG_SPIRAM_USE_MEMMAP , SPIRAM_USE_CAPS_ALLOC and SPIRAM_USE_MALLOC ? What are the pros and cons of each of the approaches? Thank you.

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

Re: SPIRAM option CONFIG_SPIRAM_USE_MEMMAP

Postby MicroController » Sat Jul 29, 2023 1:13 am

Alberk wrote:
Fri Jul 28, 2023 7:29 am
Hi,

Is there any documentation that explain the difference between CONFIG_SPIRAM_USE_MEMMAP , SPIRAM_USE_CAPS_ALLOC and SPIRAM_USE_MALLOC ? What are the pros and cons of each of the approaches? Thank you.
Docs

Basically, it's a hierarchy of functionality:
1. SPIRAM_USE_MEMMAP: Your code can access SPIRAM/PSRAM via pointers. But it's just "bare" memory so you have to manage the memory regions/addresses you use yourself; the PSRAM is like a single, huge, statically allocated byte array. May be an option if you only need one or a few large RAM areas (buffers,...).
2. SPIRAM_USE_CAPS_ALLOC: You can allocate memory from PSRAM via heap_caps_malloc(…, MALLOC_CAP_SPIRAM) (and free() it afterwards). Management of addresses and free/used regions is done by the heap manager for you so you can dynamically allocate and deallocate many smaller blocks of varying sizes, but PSRAM is only used when code explicitly requests it via heap_caps_malloc(...).
3. SPIRAM_USE_MALLOC: PSRAM can be allocated via standard malloc(...) calls too. This way, generic code (third-party,...) which only uses standard malloc(...) and may not even be aware of heap_caps_malloc/PSRAM can "automatically" use PSRAM too. This may however cause issues with some code which expects malloc(...) to allocate fast, unconditionally accessible RAM.

Alberk
Posts: 55
Joined: Sat Jun 19, 2021 1:49 am

Re: SPIRAM option CONFIG_SPIRAM_USE_MEMMAP

Postby Alberk » Sat Jul 29, 2023 1:32 am

Thank you for the detailed explanation.

Who is online

Users browsing this forum: Baidu [Spider], Corand, Google [Bot] and 112 guests