boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.14k stars 138 forks source link

Feature suggestion - static (non-dynamic) memory mode #450

Closed RonAmihai closed 4 years ago

RonAmihai commented 4 years ago

I would like to examinate possibility to combine static memory mode to the library - i.e. avoid any regular "new"/"delete" calls in some circumstances.

It can also be achieved with placement new semantics (with explicit destructor calls instead of delete) if memory allocation can't be avoided at all - this only requires buffer parameter at the injector's construction.

My motivation for this feature is cases when Boost.DI is used in memory constrained environment, i.e. embedded platforms (bare metal or RTOS). In such environment it is much cheaper to rely on statically allocated memory buffer (even big enough for all of the generated object tree) than relying on heap / dynamic memory.

What are your thoughts? Is it possible to implement this feature with the current state of the library?

krzysztof-jusiak commented 4 years ago

Sure, that's possible, I'd actually say [Boost].DI is pretty well suited for the constrained environments as it doesn't require any external dependencies and/or building a library. Regarding, the allocations there are a few customization points which you can take a look into to achieve your goals: