Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

c++ class memory consumption

Hello,

I am trying to code with cpp and now i started a blank project with a NIOS II/f processor, connected to 16KB onchip RAM, created with QSYS in the NIOS II IDE.

I took the generated .sopc file and created a bsp project with it.

Now i made a .cpp file with int main and toggled some LEDs on my Max10 FPGA Dev Kit (10m50DA), everthing OK, console tells me that 9972 Bytes are free for heap and stack.

My next step, where the memory overflows, is where i create a class, in the same cpp and header file, where my int main() function is, with empty constructor and deconstructor and a public void function, with the toggle code. The output from the console is that .text, .rwdata and so on, would start on an address where no RAM is.

Are there some docs to determine how much memory will be reserved for classes, or is the virtual key word my problem? I think vtable should be around 4Byte..?

I am new to embedded c++, i used C for NIOS up till now and have some experience with QT5.

The GCC cersion I am using is 4.8.3.

The BSP settings are basically the default settings, but with small C library and reduced device drivers, cpp is enabled.

Code is the following:

/*
 * Main.cpp
 */
# include "Main.h"
int main (){
  Main test;
  do {
    if (IORD_ALTERA_AVALON_PIO_DATA(USER_PB_BASE)==0x2){
      test.toggle_leds();
    }
  }while (1==1);
}
Main::Main ()
{
  // TODO Auto-generated constructor stub
}
Main::~Main ()
{
  // TODO Auto-generated destructor stub
}
void Main::toggle_leds(void){
  int counter = 0;
  for(counter = 0; counter <= 99999; ++counter);
  IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, 0xF);
  for(counter = 0; counter <= 99999; ++counter);
  IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, 0x0);
}

/*
 * Main.h
 *
 */
# ifndef MAIN_H_# define MAIN_H_
# include "altera_avalon_pio_regs.h"# include "system.h"
class Main
{
  public:
    void toggle_leds(void);
    Main ();
    virtual
    ~Main ();
};
# endif /* MAIN_H_ */

12 Replies