Doubts about C++ new/delete support #CPP
@torres98
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:
|
|
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:
Am i doing something wrong?
|
|
Stephanos Ioannidis
Hi,
Since there isn't any documentation about how to properly set-up a c++ applicationWe have recently added https://docs.zephyrproject.org/latest/develop/languages/cpp/index.html Any standard c++ library can't be enabledC++ standard library support requires a fully featured C library bundled in the toolchain, which is the Newlib in case of the Zephyr SDK. You cannot use the toolchain-bundled C++ standard library with the Zephyr minimal libc. these simply use the "user" heap pool available through the implementation of mallocThe `new` and `delete` operators internally make use of the `malloc` and `free` C library functions. As noted above, if you need the C++ standard library support, you must enable the Newlib -- refer to the following documentation for more details on how the Zephyr Newlib integration handles dynamic memory management: https://docs.zephyrproject.org/latest/develop/languages/c/newlib.html#dynamic-memory-management Regards, Stephanos
|
|
@torres98
Thank you so much to both of you, that solved my doubts.
|
|