Why I should use this :
instead of this:
Build a simple sketch, with empty loop() function. Put the two snippets in setup(), one at a time. Compile each, and note the sketch size and memory used. Draw your own conclusions. That is the only way you will learn.
void setup()
{
Serial.begin(115200);
float t = -12.34;
String tekst = "Nie dziala";
String Sum;
Sum = tekst + " " + String(t);
Serial.println(Sum);
}
void loop()
{
}
Sketch uses 5,290 bytes (17%) of program storage space. Maximum is 30,720 bytes.
Global variables use 222 bytes (10%) of dynamic memory, leaving 1,826 bytes for local variables. Maximum is 2,048 bytes.
void setup()
{
Serial.begin(115200);
float t = -12.34;
char buffer[40] = "Nie dziala ";
char fbuff[10];
dtostrf(t, 8, 3, fbuff);
strcat(buffer, fbuff);
Serial.println(buffer);
}
void loop()
{
}
Sketch uses 3,472 bytes (11%) of program storage space. Maximum is 30,720 bytes.
Global variables use 240 bytes (11%) of dynamic memory, leaving 1,808 bytes for local variables. Maximum is 2,048 bytes.
The char array method saves 1,818 bytes of program memory, at the cost of 18 bytes of SRAM. That information about SRAM usage is misleading, though, because the compiler can not determine, at compile time, how much SRAM will be used to create the two String instances and the dynamically allocated memory that they use to wrap the strings. At run time, the char array code will use less SRAM.