Don't use String
™. The solutions using C strings (i.e., char
arrays) are very efficient.
String
will add at least 1600 bytes of FLASH to your program size and 10 bytes per String
variable. Although String
is fairly easy to use and understand, it will also cause random hangs and crashes as your program runs longer and/or grows in size and complexity. This is due to dynamic memory fragmentation caused by the heap management routines malloc
and free
.
The most recent example of the pitfalls of String
can be seen here.
Related forum discussions:
-
Why shouldn't we have dynamic allocated memory... in embedded systems?
-
Struggling with manipulating data from serial buffer
Commentary from systems experts elsewhere on the net: -
The Evils of Arduino Strings (required reading!)
-
Memory Fragmentation, your worst nightmare (nice graphics)
Cheers,
/dev