Skip to content

C++ New allocates memory from kernel heap #18990

@vanwinkeljan

Description

@vanwinkeljan

Describe the bug

The current Zephyr C++ new implementation allocates memory from the kernel heap instead of using the same heap used by malloc.

In case a system would be configured with none, or a small, kernel heap and a large libc heap the call to new will fail even when sufficient memory is available in the libc heap.

To Reproduce
Steps to reproduce the behavior:

  • Problem was hit on private project.
  • Todo: reproduce with libcxx tests

Expected behavior

new/delete should use same memory pool as malloc/free

Impact

None useable system due to memory allocation failure.

Environment

  • OS: Linux
  • Toolchain: Zephyr
  • f9c94d4 (2.0-rc3)

Additional context

PR (#18464) was created to provide the option to disable Zephyr new/free implementation and falback to libcxx implementation which uses malloc and free internally.

One open question from the code review on PR #18464 is why zephyr provides its own implementation of new/free that specifically depends on kernel heap

Metadata

Metadata

Assignees

Labels

area: C++bugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions