Open htcrane opened 3 months ago
Hi @htcrane! We appreciate you submitting your first issue for our open-source project. 🌟
Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙
If my understanding is correct, I can open a PR to add the stubs and add some clearer documentation.
Is your enhancement proposal related to a problem? Please describe. 1) The documentation does not make it obviously clear if using
malloc()
ork_malloc()
is the preferred method for dynamic memory allocation. 2) There currently is no clean way of getting heap statistics for the standard library, such as withmallinfo()
.Describe the solution you'd like 1) Provide the user with a standard library function to understand how much memory is left for allocation via
malloc()
.mallinfo()
for structure statistics andmalloc_stats()
for printed statistics (newlib C, section 3.25)._mallinfo()
and_malloc_stats()
stubs for the standard library.HEAP_BASE
andheap_sz
.2) Provide clear documentation on why a user may want to use
malloc()
directly or stick tok_malloc()
.malloc()
is general purpose and supported no matter the standard C library chosen to build with. The memory sourced may go through a virtualization step where memory may no longer be continuous regions.k_malloc()
requires additional setup through theCONFIG_HEAP_MEM_POOL_SIZE
option and is useful if memory should be allocated from a common memory region.3) Provide a memory summary documentation page. Looking through several issues, conversations about the heap talk about the heap available to the standard c libraries (malloc) and the system heap (k_alloc) interchangeably when they do not source their memory from the same heap.
Describe alternatives you've considered
malloc()
or other heap statistics available to the standard library.29735
23076
57725
Additional context
sys_heap_runtime_stats_get()
shown in this sample. This function does not appear anywhere in the latest Zephyr documentation.cmd_kernel_heap()
, code link, also does not appear anywhere in the latest Zephyr documentation. It provides stats for the_system_heap
, which is used fork_malloc()
. This is useful for that single memory region, which is not the same memory region asheap_base
wheremalloc()
is sourcing its memory from (when using newlib).