Memory allocation for C++ classes
Posted: Fri Jul 12, 2013 11:20 am
Hello,
I'm wondering if anyone has the same problem ... I'm using C++ for my application and want to instantiate some classes at startup.
What class I have to instantiate depend on a configuration.
In a non-embedded system I would definitely use new to create an instance. But what would you recommend here in an embedded system with ChibiOS?
My first thought was to use the ChibiOS allocator and call the constructor like this:
CanProtocol* protocol = (CanProtocol*) chCoreAlloc(sizeof(CanProtocol));
*protocol = CanProtocol();
But unfortunately the vtable pointer for this instance will not be initialized with this way.
Has anyone faced this problem yet? How would you solve it?
Best regards
Mathias
I'm wondering if anyone has the same problem ... I'm using C++ for my application and want to instantiate some classes at startup.
What class I have to instantiate depend on a configuration.
In a non-embedded system I would definitely use new to create an instance. But what would you recommend here in an embedded system with ChibiOS?
My first thought was to use the ChibiOS allocator and call the constructor like this:
CanProtocol* protocol = (CanProtocol*) chCoreAlloc(sizeof(CanProtocol));
*protocol = CanProtocol();
But unfortunately the vtable pointer for this instance will not be initialized with this way.
Has anyone faced this problem yet? How would you solve it?
Best regards
Mathias