Epyon
Well-known member
Hi all
I would like to dynamically size a global array. The size is known at boot time and never changes during the program (so no heap fragmentation) and can also never be larger than a defined maximum (so no risk of running out of memory). However when I try to run the following code, it just gives me '1' for size.
I'm using new in stead of malloc() (now supported in Arduino), but C-style malloc gives the same result. I'm using Arduino 1.6.10 with TD1.28b.
I would like to dynamically size a global array. The size is known at boot time and never changes during the program (so no heap fragmentation) and can also never be larger than a defined maximum (so no risk of running out of memory). However when I try to run the following code, it just gives me '1' for size.
Code:
int* myArray = 0;
int myArraySize = 0;
void setup() {
Serial.begin(9600);
Serial.println("start");
myArraySize = 20; //some routine will calculate this size in the real program
if (myArray != 0) {
delete [] myArray;
}
myArray = new int [myArraySize];
Serial.println(sizeof(myArray)/sizeof(int));
}
void loop() {
// Here we'll do something with the array
}