How to calculate and use ESP32 memory?

Hi all.
the doc. said that ESP32-WROOM-32D (4MB HIGH TEMP), and siad:

There is 520 KB of available SRAM (320 KB of DRAM and 200 KB of IRAM) on the ESP32. However, due to a technical limitation, the maximum statically allocated DRAM usage is 160 KB. The remaining 160 KB (for a total of 320 KB of DRAM) can only be allocated at runtime as heap.

what this means?

if I have a Array[i][8] = {"xxx", "xxxxxx". "xxxxxx", "xx.xxxxxx", "xxx.xxxxxx", "xx", "xxxxxx", "xxxxxx"};
each x indicated a Arabic numerals, what can be the max. i ? possible upto 500?
thanks
adam

The first thing that you need to do is to make sure that each individual string fits in the space allocated to it. That is not the case for your example as a number of then exceed the space allocated.

Note too that each string has a hidden terminating zero that needs space to be store

Seeing a string such as "xx.xxxxxx" makes me wonder whether what is being stored is a representation of a float. Is that the case here ?

1 Like

Adam,

can you think of an empirical method how to determine how much memory an array of char uses?

1 Like

You are asking a detail question without adding informations about your project.
It might be that this is a pure academic detail-question. I don't know.

If you are planning a project with a huge array for numbers with 8 digits
example
12.345678
or
123456.78
you could use longs with moved decimal point.

example
12.345678
could be multiplied with 1000000
to result in
12.345678 * 1000000
12345678
which would only need 4 bytes of memory instead of 10 bytes as ascii-coded char-array.
8 dgits + 1 decimal point plus terminating zero = 10 bytes for 8 digits

1 Like

Thanks.
Yes, that are GPS lat/lon float.
I used the array[][] to store GPS data and got rebooting when serial.print, it's why I guess may memory question?

Thanks.

So why hold them as strings ?

1 Like

Thanks.
it's a long story, ha.
that was String stringa b c when take the date and time from GPS and save to SD, all OK.

got rebooting when read from SD and during serial print on halfway. say total 300 data in SD, rebooting at printing of 159.

I'd be looking for a bug in YOUR code...

As suggested by @StefanL38, it would be more sensible for them to be stored as raw data in the array rather than as strings. What is the rest of the data apart from the lat/long values ?

When the data is in the array what are you intending to do with it ? Does it even need to be in the array considering that you mention that the data has been saved to an SD card ?

Adam, you seem to do quick guessings what comes to your mind.

As you have posted yourself

You have this array

                  10            20            30                40
 123    456789    012345    678901234    5678901234    56    789012    345678
 123    123456    123456    123456789    1234567890    12    123456    123456
"xxx", "xxxxxx". "xxxxxx", "xx.xxxxxx", "xxx.xxxxxx", "xx", "xxxxxx", "xxxxxx"};

45 characters in 8 strings = 48 + 8 = 56 bytes

160*1024 / 56 = 2295 array elements

Here is a testcode that fills an array with 12905 elements each 8 bytes long which sums up to 103240 bytes.

#define max 12905

char myBigArray[max][8] = {

// 12905 lines with
"1234567",

};

void setup() {
  Serial.begin(115200);
  Serial.println("Setup-Start");
}

void loop() {
  for (int i = 0; i < max; i++) {
    Serial.print("i:");
    Serial.print(i);
    Serial.println(myBigArray[i]);
  }

}

compiler says
Sketch uses 364129 bytes (27%) of program storage space. Maximum is 1310720 bytes.
Global variables use 124576 bytes (38%) of dynamic memory, leaving 203104 bytes for local variables. Maximum is 327680 bytes.

So it is very likely that your code has a bug.
If you were using variable type String it might be that RAM got all eaten up by repeatedly assigning new Strings

I recommend that you start thinking loooooonger about your problems
and I recommend that you start learning throuroughly

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.