-1

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?

Thanks!

asked Oct 24, 2016 at 17:59
5
  • 1
    Write your own core. Commented Oct 24, 2016 at 18:07
  • 3
    Just don't use String - which is recommended regardless. Commented Oct 24, 2016 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. Commented Oct 24, 2016 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/… Commented Oct 24, 2016 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. Commented Oct 24, 2016 at 21:41

1 Answer 1

1

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.
answered Oct 24, 2016 at 18:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.