Hey guys,
I'm a bit confused what's the best way to store my sensors name. I'd really appreciate any information about what I am misunderstanding. My problem is that I run into a memory issue and I try to improve the memory usage - so I thought lets begin with the strings. The name of the sensor is used to identify it in debug-messages.
With either option 1a or option 1b (no option 2, no option 3, no option 4) my Arduinos RAM is used with 9 Bytes (some default stuff), I'm fine with that.
- The combination of 1a and 3 still uses 9 Bytes. I'm wondering why it is not 9 + 4x2B (for 2B/int) = 17B because it is in global scope?
- Adding option 4 I was expecting 17B + 10x1 (1B/char) = 27B - but it's still 9B?
- Adding option 2a results in 33B - why?! I still expected 27B.
- Changing 1a to 1b results in 15B, but I expected either 9B (only for the default stuff) or 14B (for copying the value -> 9 + 4x1 (1B/char from "name") + 1B (for zero-terminating of "name") - why?
- One more point: Changing now 2a to 2b still uses 15B (also 15B is the result when changing 2a to 2b in list-step 3) - I don't get it?
class cClass {
public:
cClass(){}
void setName(const char* sensorName) {
// Option 2a
//strcpy(sName, sensorName);
// Option 2b
//EEPROM.put(0, sensorName);
}
const char sName[10];
// Option 3
int a;
int b;
int c;
int d;
};
// Option 1a
cClass newC;
void setup() {
// Option 1b
//cClass newC;
newC.setName("name");
}
void loop() {
}
Many thanks in advance and best regards
Stefan