You can test that yourself; just compile it and see what the IDE tells you about memory usage.
I've placed your snippets in loop()
First one:
Sketch uses 2,566 bytes (7%) of program storage space. Maximum is 32,256 bytes.
Global variables use 124 bytes (6%) of dynamic memory, leaving 1,924 bytes for local variables. Maximum is 2,048 bytes.
Second one:
Sketch uses 2,566 bytes (7%) of program storage space. Maximum is 32,256 bytes.
Global variables use 124 bytes (6%) of dynamic memory, leaving 1,924 bytes for local variables. Maximum is 2,048 bytes.
Without context it's difficult to say what is the correct approach. Where do the numbers come from? Below a different way
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
byte values2print[] = {55, 54, 55, 56};
void setup()
{
mySerial.begin(115200);
}
void loop()
{
for (byte cnt = 0; cnt < sizeof(values2print); cnt++)
{
mySerial.write(values2print[cnt]);
}
}
Sketch uses 2,562 bytes (7%) of program storage space. Maximum is 32,256 bytes.
Global variables use 128 bytes (6%) of dynamic memory, leaving 1,920 bytes for local variables. Maximum is 2,048 bytes.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup()
{
mySerial.begin(115200);
}
void loop()
{
byte values2print[] = {55, 54, 55, 56};
for (byte cnt = 0; cnt < sizeof(values2print); cnt++)
{
mySerial.write(values2print[cnt]);
}
}
Sketch uses 2,616 bytes (8%) of program storage space. Maximum is 32,256 bytes.
Global variables use 124 bytes (6%) of dynamic memory, leaving 1,924 bytes for local variables. Maximum is 2,048 bytes.
This however only tells part of the story. Although it looks like the latter uses less memory, that is not true; at the moment that loop() is called, the array is created and hence you will have to add 4 bytes to the reported memory usage.
You can place the array in PROGMEM to save RAM.