Why a pointer to a class take less memory SRAM than a "classic" variable

i have a Arduino Micro with 3 time of flight LIDAR micro sensors welded to it. In my code i was creating 3 Global variable like this:

Adafruit_VL53L0X lox0 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox1 = Adafruit_VL53L0X();
Adafruit_VL53L0X lox2 = Adafruit_VL53L0X();

And it took like ~80% of the memory Now i am creating my objects like this

Adafruit_VL53L0X *lox_array[3] = {new Adafruit_VL53L0X(), new Adafruit_VL53L0X(), new Adafruit_VL53L0X()};

And it take 30% of my entire program

I Try to look on arduino documentation but i don't find anything that can help me. I can understand that creating a "classic" object can fill the memory. But where is the memory zone located when the pointer is create ? Thanks

Because the instances will be created at run time. No memory is allocated for the objects… so the compiler does not report it, but you will still need the memory at run time.

(It’s C++ so don’t expect to find that in the arduino doc. They focus mainly on their addd on functions and libraries)

1 Like