String Length Maximimum?

Hi. I am working on a project where I have to work with an incoming String from an user interface and write it via NFC onto a mifare transponder.
While tinkering with it I discovered that there seems to be an maximum length for Strings. But it does not seem to be a constant maximum length. It changes depending on the size of the rest of the sketch.
is that the RAM of the arduino or is it a String related problem and I should find a workaround and work e.g. with char arrays? I would like to have an idea about what limits the data before changing my whole setup.

heres the most simple test sketch in that i could simulate that behaviour. here it starts around 800 characters (which would have been fine) in the String. In my original NFC sketch the limit seemed to be reached at about 295 characters:

String message = "/*here put in a String with over 800 characters*/";

void setup()
{
  Serial.begin(9600);
  Serial.println(message);
}

void loop()
{
}

i would be very happy for an explanation. just to not start working in the wrong direction.

just to not start working in the wrong direction.

Unfortunately, you're already heading south because you're using Strings.
Yes, you should be using C strings instead.

:smiley:

thx. was afraid so. but can you tell me what exactly is causing these problems? or are you just sayin "Strings are crap anyways"?

Im gonna try around with c strings. promise :wink:

but can you tell me what exactly is causing these problems?

Take a look at the String class. You'll see for yourself. Look at all the places new and malloc (or realloc) are called (explicitly or implicitly). You have a limited amount of memory that the String class is thrashing. Stop all the thrashing by using a fixed size array.

thank you 2 so much. gonna look into that.