I'm not a real expert so I hope someone can help me.
I have two Arduino Nanos. One Master, One Slave.
The master send every 10 seconds 20 strings of 28 bytes. There is a delay between sending the strings of 5 ms.
The slave receives the 20 strings and based on the first character in the string it places the strings in separate, unique variables.
After receiving the strings I print the strings on the serial monitor. This works fine if I use: Serial.println(StringA+StringB);
The serial monitor prints the 10 rows nicely.
However, if I first create a simple calculation like StringTotal=StringA+StringB. And then print Serial.println(StringTotal); The serial monitor starts skipping lines.
Yes, don't use the String class on an AVR Arduino. They have very limited memory and the String class fragments that memory too fast. Once you are on that limit the rest of the code execution is unpredictable.
Use only c strings (character arrays) where you have exact control over memory usage.
BTW, I2C is not suited well for transmitting strings, although it works.
All variables used in interrupt context (the onReceive handler is called in interrupt context) and normal code must be declared volatile otherwise the compiler might optimize parts away.