Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By lethe
#40329
Fotonic wrote:If I parse a ~4k characters json string ESP8266 keeps rebooting with strange stack overflow errors fired over the serial port.

Sounds to me like your problem is not insufficient RAM, but you are trying to allocate a huge array on the stack. Using heap instead should fix that problem, i.e. not
Code: Select allchar buf[4096];
but
Code: Select allchar *buf = new char[4096];
// do stuff with buf...
delete[] buf;
User avatar
By eriksl
#40339 In resource limited environments (like on a microprocessor) it is often better to make sure memory allocation and use is predictable. That means: don't allocate memory on the stack but neither do it on the heap. Do it statically like this: static char buffer[4096]. That way you will never have the surprise of memory full (which includes an overwritten stack -> crash). Memory allocated like this will not end up in the image, only the symbol itself; the image will not get larger.

You may want to define a large buffer once and use it at various places, to save memory.