That would coincide with what I just found. Your method used less flash but more ram.
I used these two sketches. I think I translated your approach correctly. It took some looking, turns out it wasn't a big change. I did skip the sizeof() bits.
Sketch 1
const byte RPM_COUNT = 5;
const unsigned long RPMS[RPM_COUNT] = { 300000, 150000, 75000, 37500, 18750 };
class myClass{
unsigned long rpmSpeed[RPM_COUNT];
public :
myClass(void) { for (byte i = 0; i < RPM_COUNT; i++) rpmSpeed[i] = RPMS[i]; }
};
myClass object;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Sketch 1 compile results:
Sketch uses 624 bytes (1%) of program storage space. Maximum is 32,256 bytes.
Global variables use 29 bytes (1%) of dynamic memory, leaving 2,019 bytes for local variables. Maximum is 2,048 bytes.
Sketch 2
const byte RPM_COUNT = 5;
const unsigned long RPMS[RPM_COUNT] = { 300000, 150000, 75000, 37500, 18750 };
class myClass {
unsigned long rpmSpeed[RPM_COUNT];
public :
myClass(void) { memcpy(rpmSpeed, RPMS, RPM_COUNT); }
};
myClass object;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Sketch 2 compile results:
Sketch uses 542 bytes (1%) of program storage space. Maximum is 32,256 bytes.
Global variables use 49 bytes (2%) of dynamic memory, leaving 1,999 bytes for local variables. Maximum is 2,048 bytes.
I wonder why the extra 20 bytes?
So I changed the array size to 10 (and 100) and they both use the same ram. Flash use with memcpy() was still lower.
memcpy() wins except maybe for smaller arrays.
By the way, thanks.