Largest contiguous RAM for HEAP
Largest contiguous RAM for HEAP
Hi,
On ESP32:
Is there any way to tell malloc to first use memory fragments for heap allocation from the D/IRAM region instead of the DRAM region?
It seems to first consume the DRAM which in turn reduces the size of the largest available contiguous block.
This disallows some critical allocations in my application later on.
Thx for any help
On ESP32:
Is there any way to tell malloc to first use memory fragments for heap allocation from the D/IRAM region instead of the DRAM region?
It seems to first consume the DRAM which in turn reduces the size of the largest available contiguous block.
This disallows some critical allocations in my application later on.
Thx for any help
Re: Largest contiguous RAM for HEAP
Have you tried menuconfig ?
Re: Largest contiguous RAM for HEAP
Which entries in menuconfig? I don't want to place code in the PSRAM, there is an option to allow malloc to use PSRAM, but that is RAM is much slower.
Any hints? Thx
Any hints? Thx
Re: Largest contiguous RAM for HEAP
Refer to this for memory allocation https://docs.espressif.com/projects/esp ... alloc.html
Re: Largest contiguous RAM for HEAP
That's a good resource for heap analysis.
Unfortunately nothing is said about heap fragmentation and how to best avoid it in order to get a large as possible contiguous block.
Any more ideas?
Unfortunately nothing is said about heap fragmentation and how to best avoid it in order to get a large as possible contiguous block.
Any more ideas?
-
- Posts: 1734
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Largest contiguous RAM for HEAP
General recommendation: Reduce the number of allocations from the heap.heap fragmentation and how to best avoid it
- Use the stack/local variables instead of heap when possible
- Use statically allocated variables
- Avoid reallocations/resizing of allocations (C++ string concatenation, std::vector, ...)
- Allocate one larger block instead of multiple smaller ones.
Re: Largest contiguous RAM for HEAP
This should get the largest free block for the different memory types.
Code: Select all
size_t heap_caps_get_largest_free_block(uint32_t caps)
Re: Largest contiguous RAM for HEAP
These are good strategies, I guess there are no possibilities to change the heap allocation strategy of malloc to first get D/IRAM and then switch to DRAM, reason ist that the DRAM section is larger than the D/IRAM section.MicroController wrote: ↑Wed Oct 18, 2023 8:48 amGeneral recommendation: Reduce the number of allocations from the heap.heap fragmentation and how to best avoid it
- Use the stack/local variables instead of heap when possible
- Use statically allocated variables
- Avoid reallocations/resizing of allocations (C++ string concatenation, std::vector, ...)
- Allocate one larger block instead of multiple smaller ones.
So if malloc would first allocate from D/IRAM, the large contiguous block from DRAM would still be available.
Is there any possibility to achieve this?
Re: Largest contiguous RAM for HEAP
These are good strategies, I guess there are no possibilities to change the heap allocation strategy of malloc to first get D/IRAM and then switch to DRAM, reason ist that the DRAM section is larger than the D/IRAM section.
So if malloc would first allocate from D/IRAM, the large contiguous block from DRAM would still be available.
Is there any possibility to achieve this?
[/quote]
This will allow you to achieve the RAM allocation by hierarchy https://docs.espressif.com/projects/esp ... _t6size_tz
So if malloc would first allocate from D/IRAM, the large contiguous block from DRAM would still be available.
Is there any possibility to achieve this?
[/quote]
This will allow you to achieve the RAM allocation by hierarchy https://docs.espressif.com/projects/esp ... _t6size_tz
Re: Largest contiguous RAM for HEAP
heap_caps_malloc_prefer
only allows to separate internal from external (PSRAM) memory, but not DRAM from D/IRAM as far as I know.
For my application it is even more difficult as I use std::unique_ptr and would possible have to reimplement the allocator of std::unique_ptr.
Thanks for your help!
only allows to separate internal from external (PSRAM) memory, but not DRAM from D/IRAM as far as I know.
For my application it is even more difficult as I use std::unique_ptr and would possible have to reimplement the allocator of std::unique_ptr.
Thanks for your help!
Who is online
Users browsing this forum: No registered users and 202 guests