I would like to allocate numerous class in static memory and NOT use the heap for an embedded project using C++. Currently when we do the following to a class in a separate CPP file devoted to statically allocated classes:
Config cfg(spi);
This gets allocated on the heap from what I can tell. Stepping through the assembly code, I see malloc is eventually called. The stack trace looks like the following:
malloc()
__register_exitproc()
__static_initialization_and_destruction_0()
_GLOBAL__sub_I_periodic()
__libc_init_array
<reset vector>
The Config class looks like this:
class Config
{
public:
Config(SPIDriver &spi);
virtual ~Config();
private:
SPIDriver *_spi;
}
The implementation then looks like this:
Config::Config(SPIDriver &spi)
: _spi(&spi) {}
Config::~Config() {_spi = NULL;}
Is there any way to force GCC to place this in static memory and NOT on the heap? Thanks in advance!