0

I’m working on embedded projects, using Zephyr RTOS with ARM embedded microcontrollers like STM32 Nucleo series (Cortex M4/0).

Recently, due to significant C++ support improvements in the recent versions of Zephyr, I’m considering to move from C development to modern C++.

By default, Zephyr includes C standard library, but not Cpp’s STD.

Zephyr actually added optional support for Cpp’s standard library, which seems to work pretty well. However, it requires huge flash memory usage (near 65% of my microcontrollers flash memory, without my code!).

So I’m trying to search for alternative ways to use modern C++ without the actual standard library (including the memory/utility headers).

I’ve considered to use Boost.smart_ptr for smart pointers, but I’m wondering how I should use move semantics (std::move) In my case.

Should I use Boost.Move module? Even though I’m using C++1x and not C++0x?

Should I implement move semantics by myself using direct cast from T& to T&&?

Mishums
  • 19
  • 6
  • You can just implement `std::move` yourself in one line... Ok, you need `remove_reference` too and maybe want to do some formatting. But if all you need from the standard library is `std::move` then there's not going to be any problem. – Max Langhof Jan 10 '20 at 09:42
  • Boost (and virtually any CPP code) relies on STD i.e. includes std headers. – Igor R. Jan 10 '20 at 09:43
  • I would rather avoid STD, exceptions & RTTI – 0___________ Jan 10 '20 at 11:35
  • @IgorR. If I'm not wrong Boost have fallbacks in their internal implementations if the STD headers isn't included. I've already succeeded to use Boost.DI without STD, gonna also try smart_ptr & move but I've noticed they also have fallbacks in the source code... – Mishums Jan 10 '20 at 11:53
  • @P__J__ Of course I'm avoiding any anti embedded mechanisms like exceptions and RTTI. But smart pointers seems to be valuable for my needs so I rather not give up on this. – Mishums Jan 10 '20 at 11:56
  • @IgorR I'm afraid you're wrong, because Boost doesn't implement `::operator new()`, and `shared_ptr` dynamically allocates its control block. – Igor R. Jan 10 '20 at 11:58
  • @MaxLanghof Thanks, maybe I'll just implement this semantic myself. Anyways, do you know if there are any downside for using Boost.Move with C++1x? – Mishums Jan 10 '20 at 11:59
  • @IgorR. Actually Zephyr themselves does implement new operator (using libc/newlib internally) so this is not a big deal in my case. – Mishums Jan 10 '20 at 12:03
  • Either std::move() or boost::move() is just a typecast to &&. If your library implements `operator new`, it implements the standard library (or maybe some subset of it). – Igor R. Jan 10 '20 at 12:25

1 Answers1

1

I've just found what caused the huge flash usage of the STD.

In my case, it was inclusion of the <iostream> header (used for std::cout), without it flash usage is reasonable enough, even with std containers.

So I guess it solved my issue, I can use C++ STD for my purpose now.

(using <iostream> in embedded environment is a bad idea anyways, for printing just use printf)

Mishums
  • 19
  • 6