Hey there. So, I've been slowly converting some old Teensy ++ 2.0 code to Teensy 3.1 code. I've noticed something odd (my best guess is it's because the 3.1 is a 32 bit processor) with the RAM estimates. The following code contains a class, 'Menu,' and does nothing with it. Just instances a single object of that class (SelectModeMenu). On Teensy ++ 2.0, that object takes up 134 bytes of memory. On Teensy 3.1, it takes up 264. To test, I compiled with board selected as Teensy 3.1, once with SelectModeMenu, and once with its instancing commented out. I did the same thing with board selected as Teensy ++ 2.0. Any ideas? Do pointers or functions on Teensy 3.1 take up double the memory?
Code:
class Menu{
public:
Menu();
Menu(int id, int upid, int pid, int nid);
void setButtonExists(boolean, boolean, boolean, boolean, boolean, boolean);
void allButtonsOff(boolean);
void drawMenu();
void update();
void setButtonData(int, int, int, int, int, int);
int8_t ID; // ID # of the current menu
int8_t upID; // ID of the menu above this one in the hierarchy
int8_t prevID; // ID of the menu to the left
int8_t nextID; // ID of the menu to the right
inline void setMenuFunction(void (*fptr)()){
menuFunction = fptr;
};
private:
void (*menuFunction)();
};
Menu *menus[64];
Menu * currentMenu;
Menu::Menu(int id, int upid, int pid, int nid){
ID = id;
upID = upid;
prevID = pid;
nextID = nid;
menus[id] = this;
}
Menu SelectModeMenu (0, -1, -1, -1);
void setup(){
}
void loop(){
}
//Teensy 3.1 Menu size: 264 (with SelectModeMenu: 3712. Without: 3448)
//Teensy ++ 2.0 Menu size: 134 (with SelectModeMenu: 156. Without: 22)