mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
docs: clarify PSRAM default allocation behavior
Clarify that MALLOC_CAP_DEFAULT describes a memory capability rather than the malloc() placement policy, so PSRAM-backed capability allocations are documented correctly when malloc() remains internal-only by default. Closes https://github.com/espressif/esp-idf/issues/18391 Made-with: Cursor
This commit is contained in:
@@ -87,11 +87,13 @@ It is recommended to access the PSRAM by ESP-IDF heap memory allocator (see next
|
||||
Add External RAM to the Capability Allocator
|
||||
--------------------------------------------
|
||||
|
||||
Select this option by choosing ``Make RAM allocatable using heap_caps_malloc(..., MALLOC_CAP_SPIRAM)`` from :ref:`CONFIG_SPIRAM_USE`.
|
||||
Select this option by choosing ``Add RAM to heap_caps allocator (malloc() stays internal by default)`` from :ref:`CONFIG_SPIRAM_USE`.
|
||||
|
||||
When enabled, memory is mapped to data virtual address space and also added to the :doc:`capabilities-based heap memory allocator </api-reference/system/mem_alloc>` using ``MALLOC_CAP_SPIRAM``.
|
||||
When enabled, memory is mapped to data virtual address space and also added to the :doc:`capabilities-based heap memory allocator </api-reference/system/mem_alloc>` using ``MALLOC_CAP_SPIRAM``. Since this memory is also tagged with ``MALLOC_CAP_DEFAULT``, calls such as ``heap_caps_malloc(size, MALLOC_CAP_DEFAULT)`` can still return PSRAM pointers.
|
||||
|
||||
To allocate memory from external RAM, a program should call ``heap_caps_malloc(size, MALLOC_CAP_SPIRAM)``. After use, this memory can be freed by calling the normal ``free()`` function.
|
||||
To explicitly allocate memory from external RAM, a program should call ``heap_caps_malloc(size, MALLOC_CAP_SPIRAM)``. After use, this memory can be freed by calling the normal ``free()`` function.
|
||||
|
||||
In this mode, standard ``malloc()`` does not allocate from external RAM by default because it uses a separate default allocation policy.
|
||||
|
||||
.. _external_ram_config_malloc:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user