Hi,
I'm guessing that there is something to do with how array's access data here that I haven't yet quite figured out with pointers and/or dereferencing. I think I understand how those are meant to work - but can't get it to work :o .
I can work with the data and the compiler doesn't throw an error. But as soon as I try a Serial.println, it throws the memory usage way out of scope.
My understanding is that when I do a sizeof( gameGrid[20][20].designation), I get "1" because that is the size of the first character of the array within it. But can't get it to tell me how long the whole series of characters is - such that I can confirm that I haven't looped in 13MB of characters.
I see that the code "shrinks" when I remove items from the tileData struc (well duh) - but it removes megabytes of data if I leave only the designation within it. Those are all simply initialized variables. Is it initializing the whole grid all of these items? Even when I comment out everything but the designation, it takes up 1796 bytes
The code is as follows:
const char myDesignation = 'H';
// Grid
const int GRID_X = 40;
const int GRID_Y = 40;
const int GRID_OFFSET = 2;
typedef struct {
unsigned long serialNumber;
char designation;
byte neighbor;
} tileData;
tileData gameGrid[GRID_X][GRID_Y]; // Create game grid bucket
int gameGridOffsetX = GRID_X/GRID_OFFSET; // This is the number that is our actual zero point of the game grid - allowing for placement to the left of other tiles.
int gameGridOffsetY = GRID_Y/GRID_OFFSET;
void setup() {
Serial.begin(9600);
Serial.println("Startup");
gameGrid[20][20].designation = myDesignation;
}
void loop() {
Serial.println(gameGrid[20][20].designation);
//char check = gameGrid[20][20].designation;
//int *deep = sizeof(gameGrid[20][20].designation);
//Serial.println(*deep);
// Comes up with 256 - so I feel like I'm overloading the buffer.
delay(100);
}
Output:
Sketch uses 1664 bytes (5%) of program storage space. Maximum is 30720 bytes.
Global variables use 9796 bytes (478%) of dynamic memory, leaving -7748 bytes for local variables. Maximum is 2048 bytes.
Incidentally (another post?): why do I have to assign " gameGrid[20][20].designation = myDesignation;" within a function? Why won't it assign beneath int gameGridOffsetY = GRID_Y/GRID_OFFSET;? It says something about its type not being declared.