I have a program of about 68 kb on an arduino Due, basically it’s about 800 lines long and utilizes ten large subroutines. I communicate with Modbus field devices, various cell modems, inbound and outbound email servers, and there is also a web server to serve up html configuration pages, images, and data over a LAN. This has taken me months to make and is working great. I am finished the bulk of it and during long period testing I am encountering crashes. Nothing on the serial monitor indicates a watchdog trip or endless loop. My search for answers points to string usage and memory issues. I have used the
string1 += char(c);
scenario countless times and from what I can find this is devastating the the memory (heap no?). I walked into the infamous “string trap” I know:(. I am sure you’re all used to seeing posts about crashes and talking about string hatred and I assure you I am not looking for someone to rewrite my code and fix it because I’m too lazy. I have lost enough sleep over this to think of a few ideas to solve my issue and would like some input on them before I do some serious reworking of the various clients and servers.
I read about #include <string.h> and using those string functions(strcat() etc), I’ll lose indexOf() but worse things have happened.
How recommended and reliable is this?
There is mention of a one line fix to free(), is this doable on the Due?
I read about a reserve() function. If I use this and make a global(or not?) string that I use on all my clients and servers with lots of room to spare, say 150 bytes in size, and ensure I never exceed its limit? I would need to make it =""; often though…
I am currently putting myself through the paces of char arrays and learning the ins and outs as this has been an awakening slap in the face! My future code will have no mention of String.
Edit: open to ideas as well…