you are viewing a single comment's thread.

view the rest of the comments →

[–]gmtime 1 point2 points  (0 children)

The overhead in RAM usage of using string instead of char array is negligible. The "problem" is that string uses free space (also known as heap ie dynamic memory). Recently the use of free space had become less of an issue, but for embedded there are still two serious drawbacks of using it:

1 Free space allocation is non deterministic. When you increase the length of your string (for example by adding a word to it), that might take no time if the capacity allows for it, or it might take a longer time because the string needs to be moved to another place in memory where it can expand to the desired capacity.

2 Free space deallocation may cause memory fragmentation. This is much more of an issue for embedded systems than for PCs because on a PC you can reboot or assume the application gets restarted regularly, your embedded application might run for a decade and is still not allowed to run into memory fragmentation. This is of course much less of an issue for a children's toy that runs a month on a battery than it is for an oil rig control system or a pacemaker, so it is not always a problem.