I would like to use Boost::DI in an embedded system, where heap allocation is disabled in the whole project and everything has to be allocated on stack. In projects like this, members for objects are usually passed in constructors as references or just by values. There is no calls to std::shared_ptr, std::unique_ptr or even operator new.
It would be nice to have the option to disable usage of heap, unique and shared pointers in Boost::DI.
Actual Behavior
This is the very simple application, which just uses pseudo OutputPin object to toggle some pin (attributes was added to prevent optimizations):
Even if this code doesn't use heap allocations at all (only simple reference to OutputPin), Boost::DI has added a lot of code, which creates shared pointers and calls operator new. Below is assembly from my Cortex-M4 CPU:
Generally I don't understand, why constructor of OutputPin is invoked after the call to toggle method.
What I've tried was to change the scope of OutputPin to scoped:
It produces less code, order of calls to OutputPin is now correct, but it is still invoking operator new, and, std::_Sp_counted_ptr<OutputPin*... bodies are also still compiled.
I've tried also to add 'Custom Provider' example into that code, but nothing has changed significantly.
Expected Behavior
I would like to use Boost::DI in an embedded system, where heap allocation is disabled in the whole project and everything has to be allocated on stack. In projects like this, members for objects are usually passed in constructors as references or just by values. There is no calls to
std::shared_ptr
,std::unique_ptr
or evenoperator new
.It would be nice to have the option to disable usage of heap, unique and shared pointers in Boost::DI.
Actual Behavior
This is the very simple application, which just uses pseudo OutputPin object to toggle some pin (attributes was added to prevent optimizations):
Even if this code doesn't use heap allocations at all (only simple reference to
OutputPin
), Boost::DI has added a lot of code, which creates shared pointers and callsoperator new
. Below is assembly from my Cortex-M4 CPU:Generally I don't understand, why constructor of
OutputPin
is invoked after the call totoggle
method. What I've tried was to change the scope ofOutputPin
toscoped
:The assembly now looks like:
It produces less code, order of calls to OutputPin is now correct, but it is still invoking
operator new
, and,std::_Sp_counted_ptr<OutputPin*...
bodies are also still compiled. I've tried also to add 'Custom Provider' example into that code, but nothing has changed significantly.Steps to Reproduce the Problem
#include <boost/di.hpp>
-std=c++17 -fno-rtti -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-threadsafe-statics --specs=nano.specs
Specifications
arm-none-eabi-gcc
, 7.2.1