Hey all I am wondering if it's possible to modify the WString.cpp file to only include the commands that I need for my project since that file is so large.

I am using a Digispark arduino that is Attiny85 which only has about 6k flash memory after bootloader.

Needless to say I am almost out of flash memory and I still need to do a few things.

I am reading from a serial port (in this case, using DigiCDC for a virtual serial port).

How can I overwrite the default Strings class that looks like its built in to the IDE with my own modified String class so I can get a smaller footprint?


  • 1
    Write your own core. – Ignacio Vazquez-Abrams Oct 24 '16 at 18:07
  • 3
    Just don't use String - which is recommended regardless. – Majenko Oct 24 '16 at 18:17
  • @Majenko What can I use in place of String if I have the serial.read() data coming in as 255,255,255 which in itself crashes the ATTiny. I can only send it 255,2 without it crashing. – StealthRT Oct 24 '16 at 18:18
  • 1
    Character arrays. Pure C. You might like to read these: hackingmajenkoblog.wordpress.com/2016/02/01/… hackingmajenkoblog.wordpress.com/2016/02/04/… – Majenko Oct 24 '16 at 18:19
  • 1
    If you're crashing trying to read serial data, it isn't a flash-capacity problem; you're running out RAM. Using char-arrays instead of Strings will probably help there, too, but you'll need to look at your RAM memory allocations, too. Lots of globals, f/ex, will occupy memory that might otherwise be available for temporary use. Do they really need to occupy space for the entire run duration? If not, allocate ones that don't as local memory in the functions to that do use them; it gets returned when the function exits. – JRobert Oct 24 '16 at 21:41

You can make a copy of WString.cpp, edit it, and add it to your project. Note however that:

  1. You will have to define every method that you use. Otherwise the linker will pull WString.o from the Arduino core library in order to resolve the missing methods, and then it will complain that some methods have been defined twice.
  2. Just pruning WString.cpp from unused methods will not help: the linker is already doing that for you.
  3. To know which functions/methods of your program are taking too much flash, you can use the command avr-nm --size-sort -Crtd program.elf.
  4. I second Majenko in recommending against String objects if possible.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.