Page 1 of 1

Where is my RAM ?, i want more !

Posted: Sun May 07, 2017 5:03 am
by Nick Chung
im progamming ESP32 with arduino IDE. I choose ESP32 because It has big RAM and ROM, super Fast clock.
But,Why esp32' RAM is smaller than i though (500k) ?. Just 299912 bytes RAM . hummmm. :( :(
I used 130000 byte for a BIG array. i think my skecth will around 170000 bytes. (It's free about 120000 bytes ). But it doesn't work !
its not my falt. When i resize that BIG array to 90000 bytes and it worked well as i want. :P
So i think the problem is LOW RAM .
Can you explan ? i want more 299912 bytes RAM . :cry:

Re: Where is my RAM ?, i want more !

Posted: Mon May 08, 2017 3:12 am
by WiFive
Ram is shared with wifi, TCP/IP, cache and freertos. If you disable those things you can have more ram. The problem is probably because ram is divided up into different sections and your huge array can't fit into one section.

Also you can wait for new modules with 4mbyte extra ram

Re: Where is my RAM ?, i want more !

Posted: Mon May 08, 2017 3:32 am
by ESP_igrr
Also don't forget that 328k of RAM is usable as DRAM, the other 192k is IRAM (instruction RAM).
Out of 328k, as WiFive has mentioned, parts are used by the RTOS and WiFi/BT stacks.

I suppose that the available RAM estimation in Arduino IDE may be working incorrectly in case BT is enabled in menuconfig:
https://github.com/espressif/arduino-es ... ds.txt#L11
This assumes that BT stack is not reserving part of DRAM for BT controller exchange memory. So the actual available size may be ~64 less.

Re: Where is my RAM ?, i want more !

Posted: Mon May 08, 2017 2:45 pm
by Nick Chung
Here is my code, just Examples.:

Code: Select all

uint8_t b[130000];// 130k bytes

void setup() {
Serial.begin(9600);

}

void loop() {
Serial.println("Ok !");
b[1]=0;
delay(1000);
}
"Sketch uses 105,566 bytes (10%) of program storage space. Maximum is 1,044,464 bytes.
Global variables use 139,492 bytes (47%) of dynamic memory, leaving 155,420 bytes for local variables. Maximum is 294,912 bytes."


But it's not working !
When i change b[130000] is b[100000] -> it works.
Then i tryed to read a document (esp32) talking about Array and Heap - Stack Memory erea.
(I added Static before ), the code is :

Code: Select all

static uint8_t b[130000];// 130k bytes

void setup() {
Serial.begin(9600);

}

void loop() {
Serial.println("Ok !");
b[1]=0;
delay(1000);
}
It worked!

The next section:
I fix all Array is Static but it just work when array's size smaller 90k bytes. I fail! :(
I'm thinking about use External RAM like SPI ram (23lc1024) or PC ram to get more data....haizzzz

Re: Where is my RAM ?, i want more !

Posted: Wed Feb 28, 2018 1:51 am
by maneco
I have the same problema, in latest arduino esp32 integration 96000 is máximum, but there should be 280k available acording to the man himself:
"Just to expand on what @me-no-dev said: 520KB is the total amount of RAM. That includes IRAM (instruction RAM), DRAM (data RAM), and RTC memory. "System and memory" chapter of the ESP32 Technical reference manual has a table explains this in more detail. Specifically, there is 328 KB of DRAM available on the chip (the rest is IRAM and RTC RAM). Some of that is used by the OS, some is used by tasks created during SDK startup. An empty application which just prints the amount of available heap will report ~300KB of free heap, in the latest IDF.
Enabling features such as WiFi, BT, and dual core support, reduces the amount of memory available to applications. I guess this is where the 280KB number comes from."

my code looks like this:

Code: Select all

#define MAX_DELAY 96000
uint8_t sDelayBuffer0[MAX_DELAY];
if i up that 96000 value, esp32 enters a reset loop after compilation

Any help?

Re: Where is my RAM ?, i want more !

Posted: Wed Feb 28, 2018 5:11 pm
by maneco
region `dram0_0_seg' overflowed by 26056 bytes

that's what i get in my sketch when compiling for more than 96000

Code: Select all

#define MAX_DELAY 130000
static uint8_t sDelayBuffer0[MAX_DELAY];

Re: Where is my RAM ?, i want more !

Posted: Thu Mar 01, 2018 1:42 am
by ESP_Sprite
A few things:
- While it may have changed, not all RAM is available as statically-allocated (ie the way you allocate it now) RAM, because for some regions, the compiler/linker cannot know if it'll be available at run-time. If you allocate memory using malloc() or the c++ 'new' operator you won't have this issue.
- The RAM does not consist of one contiguous chunk. The largest chunk possibly is something like 100K or so, so that's the value you see. If you allocate multiple small bits of memory, you will see that you can easily allocate more than this amount, because the heap allocator doesn't need to return the one contiguous chunk to you.

Re: Where is my RAM ?, i want more !

Posted: Thu Mar 01, 2018 4:16 am
by maneco
Thanks for your help;
i tried the three posible solutions you mentioned , new , malloc() and splitting into two chunks of memory, and problema is exactly the same
once you go past 96000 , you'll get continous reset loop ; when splitting into two buffers, once you exceed 96000 in the sum of both, problema is the same

Code: Select all

byte *sDelayBuffer0 = ( byte* ) malloc( 48000 );
byte *sDelayBuffer1 = ( byte* ) malloc( 48000 );
Could this mean that in practical terms , in arduino esp32 all we have of the 280 k left by everything else, is just 96000 bytes?
thanks again!

Re: Where is my RAM ?, i want more !

Posted: Fri Apr 15, 2022 2:59 pm
by moefear85
if you're doing this in arduino, there's almost no way you'll find more than 96000 as a single chunk. I ran into this often. Using pure esp-idf I can easily create 130000 with no problem, even as static. Infact, I was able to go up to 165492.