Hello everyone.
I'm struggling myself, but I'm sure someone has had this problem before and will give some suggestions. I'm loading a file, 20kB, into a string (SPIFFS or LittleFS - makes no difference), substituting some strings and saving in a second file. As long as the file was small (I can't remember, maybe 10kB, but I'm guessing), it all worked fine. Now I see that once every few writes the processor reboots. I've turned on debug and I get the message every so often:
[String] Reallocating large String(191 -> 192 bytes) [.......] Then I guess the stack overflows, in any case a reboot occurs.
I can split this file into several smaller ones, but it messes up my concepts. I would prefer to know how to handle this. I'm not a programmer, and I'm sure there's someone here who knows right away whether to put this in some kind of array or solve it in yet another way.
I'm not a programmer, please don't shout
.
It simply loads the contents of the file into a string variable:
String Config_Webpage = "";
File file_init = LittleFS.open("/config_init.html", "r");
file_init.setTimeout(5000); // could be 1000, could be 5000, makes no difference - anticipate the question why so much
if (file_init) {
Config_Webpage = file_init.readString();
}
I thought the program was crashing when writing to the file, but I did the traps and debug after RS showed that it was already crashing at the file read stage. Does anyone know how much you can "fit" in a String type variable ?
I'd just like to add that if I declare an array with a fixed size, this won't quite solve the problem either, as this file can have a different size (+/- 1kB). I wouldn't want to permanently allocate an area of memory, because it's known that there's not enough of that all the time. Unless I can somehow neatly allocate and release.
Please help, because I don't want to compromise myself any further, and something tells me that such problems were solved ages ago....
Regards,
Mariusz
I'm struggling myself, but I'm sure someone has had this problem before and will give some suggestions. I'm loading a file, 20kB, into a string (SPIFFS or LittleFS - makes no difference), substituting some strings and saving in a second file. As long as the file was small (I can't remember, maybe 10kB, but I'm guessing), it all worked fine. Now I see that once every few writes the processor reboots. I've turned on debug and I get the message every so often:
[String] Reallocating large String(191 -> 192 bytes) [.......] Then I guess the stack overflows, in any case a reboot occurs.
I can split this file into several smaller ones, but it messes up my concepts. I would prefer to know how to handle this. I'm not a programmer, and I'm sure there's someone here who knows right away whether to put this in some kind of array or solve it in yet another way.
I'm not a programmer, please don't shout

It simply loads the contents of the file into a string variable:
String Config_Webpage = "";
File file_init = LittleFS.open("/config_init.html", "r");
file_init.setTimeout(5000); // could be 1000, could be 5000, makes no difference - anticipate the question why so much
if (file_init) {
Config_Webpage = file_init.readString();
}
I thought the program was crashing when writing to the file, but I did the traps and debug after RS showed that it was already crashing at the file read stage. Does anyone know how much you can "fit" in a String type variable ?
I'd just like to add that if I declare an array with a fixed size, this won't quite solve the problem either, as this file can have a different size (+/- 1kB). I wouldn't want to permanently allocate an area of memory, because it's known that there's not enough of that all the time. Unless I can somehow neatly allocate and release.
Please help, because I don't want to compromise myself any further, and something tells me that such problems were solved ages ago....
Regards,
Mariusz