Teensy 3.1 Excessive RAM estimates?

Status
Not open for further replies.

MuShoo

Well-known member
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)
 
The Teensy 3.x uses the ARM Cortex M4 processor which is 32-bits, so pointers and "int" are going to twice as big as they were on the Teensy++2.
[edit] If the integers in your structures only need to be 16-bits you can change "int" to uint16_t (unsigned) or int16_t (signed) to force them to be 16-bits.

Pete
 
OK, that's basically what I figured. Sucks that my menus will all be 2x as large, but having 4x the memory (and not having to deal with PROGMEM!) on the 3.1 should make up for it! I've still got twice as much room for menus. Don't know if I'd really need four times as many menus.

Thanks!
 
Status
Not open for further replies.
Back
Top