Disclaimer: I'm an intermediate programmer, all the low level C/C++ and microcontroller programming is new to me though. I know how pointers work, but I haven't applied them in this field.
I'm currently embarking on the mystical realm that is microcontroller programming, and I'm running into an anomaly that I can't explain.
I've created a simple program for treating an input pin as a toggle button, nothing fancy. It contains simple boolean logic, calls digitalRead, has two booleans and an unsigned char as members, and takes up three bytes of RAM, according to sizeof. I've put it on Github
if you need to know more.
If I create a new instance of this class like
the program's total size (according to the compiler log) is 1218 bytes.
However, if I create the instance with new, like
ToggleButton::ToggleButton* toggleButton = new ToggleButton::ToggleButton(BUTTON_PIN);
the sketch suddenly becomes 1774 bytes.
I can't figure out where this increase in size comes from, or how I can avoid it, because 550 bytes is a pretty significant increase if you only have 32k, and I really want to use C++ and object oriented programming.
Can anyone enlighten me?