Re: Doubts about C++ new/delete support #CPP


Carles Cufi
 

Hi there,

 

I think exceptions need some extra work to be thread-safe, but Stephanos should know more.

Regarding the lack of documentation, we do have:

https://docs.zephyrproject.org/latest/develop/languages/cpp/index.html

 

Thanks,

 

Carles

 

From: users@... <users@...> On Behalf Of lucatorresetti via lists.zephyrproject.org
Sent: 09 June 2022 14:55
To: users@...
Subject: [Zephyr-users] Doubts about C++ new/delete support #CPP

 

Since there isn't any documentation about how to properly set-up a c++ application i'll ask here some questions about the topic. In issue #18990 it was pointed out the use of the kernel heap pool for the new and delete operators, and since then these simply use the "user" heap pool available through the implementation of malloc. After looking around, i found out that the (supposedly) right way of setting up the size of the user heap is through the option CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE. This seems to work correctly in a really basic c++ application, but there are a couple of pretty bad drawbacks:

  • I can't find a way to make exceptions work (for them to be enabled i need to turn off CONFIG_MINIMAL_LIBC, which i can't)
    • As a direct consequence, new can't raise std::bad_alloc when the allocation fails
  • Any standard c++ library can't be enabled (CONFIG_NEWLIB_LIBC or CONFIG_LIB_CPLUSPLUS seem to automatically set to zero CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE)

Am i doing something wrong?

Join users@lists.zephyrproject.org to automatically receive all group messages.