Hello,
I am trying to optimize memory usage and learn more about the different options.
I avoid using Strings, I use c chars or c char arrays.
I notice in my installation (IDE 2.0.4) that Global use report given by the compiler is sometimes the same if I comment out a line of code that requires space,
I send a small piece of code.
// GLOBAL VARIABLES AND CONSTANTS
int myData [20] [40];
byte arPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, //Pins to be set
10, 11, 12, 13, 14, 15, 16, 17};
char caOwner[21];
const
char caVersion[21] = "Version 1.4.12";
char caVersion2[1000] = "Version 1.4.12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
unsigned int iaParms[4];
unsigned int iaSchedule[12];
unsigned int iaCycles[12];
unsigned int iPeriodMinutes;
unsigned int iPeriodSchedule;
unsigned int iMinFirstServe;
unsigned int iMinLastServe;
unsigned int iPeriodUnit;
unsigned int iNumServe;
unsigned int iFeedSeconds;
unsigned int iHHMMFirstServe;
unsigned int iHHMMLastServe;
unsigned int iError;
// CONFIG DATA
// VOLTMETER
float fVolt = 0;
int iInVoltage = 0;
// LCD
char cOutFirstLine[21]; // output from string functions placed here
char cOutSecondLine[21]; // output from string functions placed here
char cOutThirdLine[21]; // output from string functions placed here
char saBuff[21];
// SIGNALS FOR TRANSISTOR/OPTOCOUPLERS
const unsigned int iPerifPin = 3;
const unsigned int iDrivePin = 4;
const unsigned int iCallerPin = 5;
const unsigned int iShakePin = 6;
// For RUNNING DATA
const unsigned int iSirenSeconds = 60;
const unsigned int iWaitSeconds = 60;
const unsigned int iTimeError = 5000;
const unsigned int iMealIndex[12][12] = {
{ 3,12,12,12,12,12,12,12,12,12,12,12},
{ 3, 9,12,12,12,12,12,12,12,12,12,12},
{ 0, 3, 9,12,12,12,12,12,12,12,12,12},
{ 0, 3, 6, 9,12,12,12,12,12,12,12,12},
{ 0, 1, 3, 6, 9,12,12,12,12,12,12,12},
{ 0, 1, 3, 4, 6, 9,12,12,12,12,12,12},
{ 0, 1, 3, 4, 6, 7, 9,12,12,12,12,12},
{ 0, 1, 3, 4, 6, 7, 9,10,12,12,12,12},
{ 0, 1, 2, 3, 4, 6, 7, 9,10,12,12,12},
{ 0, 1, 2, 3, 4, 5, 6, 7, 9,10,12,12},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,12},
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11},
};
void setup()
{
Serial.begin(9600);
Serial.println("Testing log to serial port");
delay(1500);
}
void loop() {
while(1) {
Serial.println("Looping !!!");
delay(3000);
}
}
Compiler answers:
Sketch uses 1712 bytes (5%) of program storage space. Maximum is 32256 bytes.
Global variables use 226 bytes (11%) of dynamic memory, leaving 1822 bytes for local variables. Maximum is 2048 bytes.
If I comment out from start of GLOBAL lines of code, to line 62, at the end of Globals definitions, results are still 226 bytes.
What am I missing or bad interpreting?
Thanks for you help !
Horacio