String objects vs character arrays ...

I have seen a number of comments in the past about the issues with String objects and memory fragmentation etc. They have often said "see this for a good discussion". Now that I want do do some things with strings (or character arrays), for the life of me, I can't find a pointer to what was apparently a good discussion of the issues. Can someone point me in the correct direction? (yes, I do understand the difference between the String object and a character array) - Strings are certainly easier for simple things (building messages etc.) but I don't want to have something that runs for a few days etc. then crashes because of issues with memory. Pointers (so to speak) appreciated.

Look at The Evils of Arduino Strings for example

Here's a summary I try to keep updated. It includes a link to Majenko's excellent description.

Now that I want do do some things with strings (or character arrays)

Glad to hear it! There are many tricks in this area, but strcpy, strcat, strlen and strstr are some of the best. There are also xxxxx_P variants that use F("flash strings") instead of RAM-based "double-quoted string literals". :slight_smile:

Cheers,
/dev

Perfect ! Exactly what I was looking for J-M-L. Thanks much! Saved a copy for myself (with a couple of spelling errors fixed :slight_smile: ). He does a good job of describing the problems. Off to declare some character arrays for me!

Thanks /dev for your links also - interesting to note the link in there about "dynamic memory forbidden in avionics systems" - very true - I spent a number of years in commercial avionics and for some reason, passengers get very nervous about software doing strange things when it is running control surfaces etc :slight_smile: (we had to live by DO-178B which really locked things down and ensured very through testing and documentation of the software)

Strings are like kitchen knives: when used correctly, there is little reason to believe you will cut your finger off.

Strings, as a class, is perfectly legitimate. You must exercise some neurons in thinking through what you are doing and in propetly pre-allocating storage.

Ray