Largest contiguous RAM for HEAP

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

Re: Largest contiguous RAM for HEAP

Postby Alberk » Wed Oct 18, 2023 9:23 am

If you are going to use the IRAM memory there are limitation that you must be aware off. https://esp32.com/viewtopic.php?t=23891#p94825

ESP_jakob
Posts: 49
Joined: Mon Jun 01, 2020 6:28 am

Re: Largest contiguous RAM for HEAP

Postby ESP_jakob » Wed Oct 18, 2023 10:30 am

If you really don't want allocations to happen in a certain area, have you tried "reserving" it by doing the allocation before the other (smaller) allocations? If you need that space temporarily, you can still try to assign memory from the "reserved" space temporarily, effectively implementing your own memory management.

A really naive solution, but it might work.

rma-31
Posts: 15
Joined: Sun Oct 08, 2017 5:07 pm

Re: Largest contiguous RAM for HEAP

Postby rma-31 » Wed Oct 18, 2023 10:56 am

ESP_jakob wrote:
Wed Oct 18, 2023 10:30 am
If you really don't want allocations to happen in a certain area, have you tried "reserving" it by doing the allocation before the other (smaller) allocations? If you need that space temporarily, you can still try to assign memory from the "reserved" space temporarily, effectively implementing your own memory management.

A really naive solution, but it might work.
This is what I have tried:
- Reserve large block temporarly
- Do smaller things
- Free large block for large allocation
- Allocate large block (done unter the hood by std::make_unique<>())
- SOME RTOS/IDF RELATED DYNAMIC ALLOCATIONS MAY OCCUR?!?!
- Free large block (destroy unique_ptr object)
- SOME RTOS/IDF RELATED DYNAMIC ALLOCATIONS MAY OCCUR?!?!
- Try to reallocate the large block with std::make_unique<>() -> error large block is not available any more

It seems that whatever dynamic allocation stuff is going on in between, maybe from RTOS and/or IDF somehow shrinks the heap area which contains the large block so that eventually one can't allocate the large contiguous block anymore.

If one could tell malloc to allocate first from D/IRAM as priority, then maybe the large block (DRAM) stays untouched.

Hmm, not an easy one, I guess...

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

Re: Largest contiguous RAM for HEAP

Postby MicroController » Wed Oct 18, 2023 12:14 pm

https://docs.espressif.com/projects/esp ... ble-memory
-> "MALLOC_CAP_32BIT" allows heap_caps_malloc to allocate from IRAM.

rma-31
Posts: 15
Joined: Sun Oct 08, 2017 5:07 pm

Re: Largest contiguous RAM for HEAP

Postby rma-31 » Wed Oct 18, 2023 1:08 pm

I think there is this flag, which may influence the behaviour:
CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY
https://docs.espressif.com/projects/esp ... ble-memory

But I can't find this option any more in idf.py menuconfig, it is not in the referenced section :(

rma-31
Posts: 15
Joined: Sun Oct 08, 2017 5:07 pm

Re: Largest contiguous RAM for HEAP

Postby rma-31 » Wed Oct 18, 2023 1:14 pm

This flag is another interesting one https://docs.espressif.com/projects/esp ... e-internal

When SPIRAM allocation with malloc are enabled, it is possible to reserve a block of RAM for "specific needs" such as DMA etc.
If this is enabled, how do the "specific needs" allocate from this reserved memory?

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

Re: Largest contiguous RAM for HEAP

Postby MicroController » Wed Oct 18, 2023 6:27 pm

As usual, via heap_caps_malloc().

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 236 guests