Replacing stock String.cpp with smaller version

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).

Currently I am trying to read in 255,255,255 but it crashes (freezes up) the digispark. I seem to be able to only send 255,2 for it not to crash. I gather its doing this because its out of memory?

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!

I'd ditch the String class altogether.

AWOL: I'd ditch the String class altogether.

Any code examples using something other than strings?

StealthRT:
Any code examples using something other than strings?

strings are fine, it’s String that’s the problem.

Whats the difference between String and string?

"String" is a class, a string is just a null-terminated char array, but with an extensive set of handling functions.

When defining a variable I do:

String blah;

So are you saying I can do:

string blah;

no not string blah;that does not exist (unless you create a string class)

char * blah;

and do memory allocation and management

No, I'm not saying that at all. The compiler has already told you that there is no datatype called "string"

No. They’re char arrays

char blah[4];

To hold three character string.

But to answer your original question, the linker is already throwing out code you don’t use. Deleting those functions from the library would gain you nothing.

Post the code and maybe someone can help you find some memory savings.

Delta_G: No. They're char arrays

char blah[4];

To hold three character string.

But to answer your original question, the linker is already throwing out code you don't use. Deleting those functions from the library would gain you nothing.

Post the code and maybe someone can help you find some memory savings.

So if I am sending 255,255,255 thru the USBSerial port read() then I would need to do this?

char blah[14]

Probably. Possibly not.

StealthRT: So if I am sending 255,255,255 thru the USBSerial port read() then I would need to do this?

char blah[14]

Need more code to answer. Is that all one string? If so you need 11 characters plus a null terminator so a char array 12 members deep.

My code:

#include <DigiCDC.h>
#include <Adafruit_NeoPixel.h>
//                                          |-Number of RGB Leds
//                                          |  |-Number of digispark pin
//                                          |  |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 2, NEO_GRB + NEO_KHZ800);

void setupo() {
     SerialUSB.begin();
     strip.begin();
}

void loop() {
     String theD;
     String blah;

     while (SerialUSB.available())
     {
          char recieved = SerialUSB.read();
          theD += theD;

          if (recieved == '\n')
          {
              blah += theD;
              SerialUSB.print(blah);
              //TODO
              //                  |-red color                |-red color
              //                  |   |-green color          |        |-green color
              //                  |   |   |-blue color       |        |        |-blue color
              //                  |   |   |                  |        |        |
              //convert blah into XXX XXX XXX array example: blah[0], blah[1], blah[2]
              //then send to fiao function. example: fiao(255,255,255,10);
              SerialUSB.println("");
              theD = "";
          }
     }

     SerialUSB.delay(10);
}

void fiao(uint8_t red, uint8_t green, uint8_t blue, uint8_t wait) {
     for(uint8_t b = 0; b <255; b++) {
         for(uint8_t i=0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
         }
         
         strip.show();
         delay(wait);
      };

     for(uint8_t b=255; b > 0; b--) {
         for(uint8_t i = 0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, red * b/255, green * b/255, blue * b/255);
         }

         strip1.show();
         delay(wait);
      };
};

theD += theD;That's going to gobble-up RAM pretty quick for no useful outcome.

void setupo() Do you ever call setupo?

char recieved = SerialUSB.read();
          theD += theD;

Do you really want to repeat copy theD whenever you receive a character? Wouldn't it make sense to keep up with the characters as you get them?