# ESP32 Compiler Error "DRAM segment data does not fit"

**URL:** <https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622>\
**Category:** Programming\
**Created:** [April 30, 2023, 10:55pm UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622 "2023-04-30T22:55:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![imk123](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/imk123/32/1013044_2.png) [@imk123](https://forum.arduino.cc/u/imk123)\
**Post date:** [April 30, 2023, 10:55pm UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/1 "2023-04-30T22:55:48Z")

</div>

Hello,  
Just starting out on ESP32 and have some DOIT DEVKIT1 ESP32 WROOM-32 boards.  
I have a Serial to WiFi Modem ESP NOW project working and now just starting out on my 2nd project that needs a number of 40kbyte 2D arrays.  
App A compiler OK but App B fails with compile error "DRAM segment data does not fit"  
After compile of App A report is:  
Global variables use 102816 bytes (31%) of dynamic memory, leaving 224864 bytes for local variables. Maximum is 327680 bytes.  
Which means I have loads more space for LocalMapThree[][]  
Any ideas please, many thanks in advance IMK

--------------- Begin App A ---------------------  
// Include Libraries  
#include \<esp\_now.h\>  
#include \<WiFi.h\>  
#include \<esp\_wifi\_types.h\>  
#include \<esp\_wifi.h\>

unsigned char LocalMapOne[201][201];  
unsigned char LocalMapTwo[201][201];

void setup()  
{ // put your setup code here, to run once:  
LocalMapOne[0][0] = 0;  
LocalMapTwo[0][0] = 0;  
}

void loop()  
{ // put your main code here, to run repeatedly:  
}  
--------------- End App A ---------------------

--------------- Begin App B ---------------------  
// Include Libraries  
#include \<esp\_now.h\>  
#include \<WiFi.h\>  
#include \<esp\_wifi\_types.h\>  
#include \<esp\_wifi.h\>

unsigned char LocalMapOne[201][201];  
unsigned char LocalMapTwo[201][201];  
unsigned char LocalMapThree[201][201];

void setup()  
{ // put your setup code here, to run once:  
LocalMapOne[0][0] = 0;  
LocalMapTwo[0][0] = 0;  
LocalMapThree[0][0] = 0;  
}

void loop()  
{ // put your main code here, to run repeatedly:  
}  
--------------- End App B ---------------------

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [May 1, 2023, 9:12am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/2 "2023-05-01T09:12:44Z")

</div>

> [@imk123](#):
>
> Any ideas please

There may exist a limit in static RAM allocation, also stack size. Try to locate and check related values in your board or project settings.

Have you enabled extended compiler diagnostics?

---

<div class="post-metadata">

**Author:** ![imk123](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/imk123/32/1013044_2.png) [@imk123](https://forum.arduino.cc/u/imk123)\
**Post date:** [May 1, 2023, 9:49am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/3 "2023-05-01T09:49:50Z")

</div>

Seems to be an ESP32 RAM (multiple types) architecture issue.  
malloc seems to works, as each malloc report's OK  
Many thanks for the reply IMK

char _pLocalMapOne = (char_)malloc( 201 \* 201 );  
if( pLocalMapOne )  
Serial.println("Malloc pLocalMapOne Ok");  
else  
Serial.println("Malloc pLocalMapOne Failed");

char _pLocalMapTwo = (char_)malloc( 201 \* 201 );  
if( pLocalMapTwo )  
Serial.println("Malloc pLocalMapTwo Ok");  
else  
Serial.println("Malloc pLocalMapTwo Failed");

char _pLocalMapThree = (char_)malloc( 201 \* 201 );  
if( pLocalMapThree )  
Serial.println("Malloc pLocalMapThree Ok");  
else  
Serial.println("Malloc pLocalMapThree Failed");

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [May 1, 2023, 10:11am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/4 "2023-05-01T10:11:13Z")

</div>

> [@imk123](#):
>
> char _pLocalMapOne = (char_)malloc( 201 \* 201 );

You see the modified display of your code?  
That's why `<CODE>` should be used to present code. You can edit your post, select the code and click `<CODE>`.

---

<div class="post-metadata">

**Author:** ![imk123](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/imk123/32/1013044_2.png) [@imk123](https://forum.arduino.cc/u/imk123)\
**Post date:** [May 1, 2023, 10:38am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/5 "2023-05-01T10:38:06Z")

</div>

> [@DrDiettrich](#):
>
> That's why `<CODE>` should be used to present code. You can edit your post, select the code and click `<CODE>`.

Hello DrDiettrich  
I find this abomination of so called standard C/C++ layout ugly and very difficult to read and follow as bits of code are floating all over the page and if( ! is easier to read with my tired old eyes than if (! as (! tend to visually merge where ( ! is much clearer.  
That is why i like the style that I have been using since my days doing C on a VAX/VMS in 1980 something . I accept your tip and many thanks IMK, but in my mind we are teaching bad behaviour as the other I accidentally hit the format function in IDE2 (which I love) and it put the ;  
of a do while() half way down the page??. Madness! 🙂

Did the edit code function for you and it didn't work, There is a God! 🙂

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [May 1, 2023, 11:05am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/6 "2023-05-01T11:05:21Z")

</div>

> [@imk123](#):
>
> I find this abomination of so called standard C/C++ layout ugly

The layout is not the big problem, instead it's all the suppressed stars:

> [@imk123](#):
>
> char _pLocalMapOne = (char_)malloc( 201 \* 201 );

should read  
`char *pLocalMapOne = (char*)malloc( 201 * 201 );`

> [@imk123](#):
>
> IDE2

I wonder how long the first usable IDE2 will take ☹

> [@imk123](#):
>
> Did the edit code function for you and it didn't work,

You did not edit any of your posts. Try again with post #3.

> [@imk123](#):
>
> doing C on a VAX/VMS in 1980

Didn't have C on our pdp's. Hit C on my Atari ST with horrible compilers. Wrote everything in GfA Basic on the ST until Visual Basic and Delphi was available on a PC.

---

<div class="post-metadata">

**Author:** ![imk123](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/imk123/32/1013044_2.png) [@imk123](https://forum.arduino.cc/u/imk123)\
**Post date:** [May 1, 2023, 11:37am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/7 "2023-05-01T11:37:13Z")

</div>

Hello DrDiettrich  
point taken about the '\*' for some reason they seemed to disappear, I love magic tricks just someone people don't seem to understand when to use them. There's another forum I post to where they insist on four spaces before and code. Oh well "different strokes for different folks", life is wonderful :-). Moring I have had includes "The lady across the road doesn't understand boyle's law when it comes to the static pressure in her combi boiler"  
Thanks for the help, IMK who's heading into garden to get the summer flower beds laid 🙂  
PS My first PC C was using MS Quick C under PC DOS 3.3 and token ring networking

---

<div class="post-metadata">

**Author:** ![imk123](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/imk123/32/1013044_2.png) [@imk123](https://forum.arduino.cc/u/imk123)\
**Post date:** [May 2, 2023, 10:25am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/8 "2023-05-02T10:25:14Z")

</div>

I did edit the post and tried to use the _Preformatted text_ toolbar button `<CODE/>`, or the backtick `.  
There is -------------------------- NO SUCH TOOL ON THE TOOL BAR --------------------------------

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 29, 2023, 10:26am UTC](https://forum.arduino.cc/t/esp32-compiler-error-dram-segment-data-does-not-fit/1121622/9 "2023-10-29T10:26:04Z")

</div>

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