<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Two simultaneous heaps combining: kernel heap and libc heap</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/127874/two-simultaneous-heaps-combining-kernel-heap-and-libc-heap</link><description>Hello Support team, 
 
 I have an issue with two simultaneous heaps in my project. I use nrf Connect SDK 3.2.2 with the next configuration options: 
 
 CONFIG_REQUIRES_FULL_LIBCPP =y 
 
 CONFIG_HEAP_MEM_POOL_SIZE =64536 
 
 By default I have Picolibc</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 Apr 2026 19:06:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/127874/two-simultaneous-heaps-combining-kernel-heap-and-libc-heap" /><item><title>RE: Two simultaneous heaps combining: kernel heap and libc heap</title><link>https://devzone.nordicsemi.com/thread/565641?ContentTypeID=1</link><pubDate>Tue, 28 Apr 2026 19:06:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04c585b8-fa9e-452b-a08e-1daa00dff436</guid><dc:creator>Egor Dolgalev</dc:creator><description>&lt;p&gt;Hi Priyanka,&lt;/p&gt;
&lt;p&gt;I tried it. To set any value to&amp;nbsp;&lt;span&gt;CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE I have to enable&amp;nbsp;CONFIG_COMMON_LIBC_MALLOC. Enabling&amp;nbsp;CONFIG_COMMON_LIBC_MALLOC leads to malloc function compilation and I have conflict with my malloc implementation&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two simultaneous heaps combining: kernel heap and libc heap</title><link>https://devzone.nordicsemi.com/thread/565602?ContentTypeID=1</link><pubDate>Tue, 28 Apr 2026 08:29:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a13cf4d-4db0-4cf9-91ff-191bdf3a5b48</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi Egor,&lt;/p&gt;
&lt;p&gt;Could you try to allocate:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE&lt;/span&gt;&lt;span&gt;=1&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;instead of leaving it 0 ? (It&amp;#39;s just to satisfy the condition, but the actual allocation should go through your overriden method.)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please try this and let me know how it goes.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Priyanka&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two simultaneous heaps combining: kernel heap and libc heap</title><link>https://devzone.nordicsemi.com/thread/565368?ContentTypeID=1</link><pubDate>Thu, 23 Apr 2026 08:18:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59db54a7-1bc2-4c93-8b97-5e4a6c5444db</guid><dc:creator>Egor Dolgalev</dc:creator><description>&lt;p&gt;Justin,&lt;/p&gt;
&lt;p&gt;Thank you for this hints. I managed it with the next changes:&lt;/p&gt;
&lt;p&gt;1. Override only C allocation functions malloc, calloc, realloc and free to kernel equivalents. Did several experiments and I see that C++ allocation is done via these C functions&lt;/p&gt;
&lt;p&gt;2. Exclude Libc implementation of allocation functions and set heap arena size to 0 using next config:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_COMMON_LIBC_MALLOC&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE&lt;/span&gt;&lt;span&gt;=0&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_COMMON_LIBC_CALLOC&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_COMMON_LIBC_REALLOCARRAY&lt;/span&gt;&lt;span&gt;=n&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;It looks like these approach works in my case. May be you can add something to it.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;hr /&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;But I faced with one issue for handling Settings subsytem over the MCU manager. I want to handle settings write and read using heap to not to allocate too much stack for McuMgr thread because we do settings read/write only during production stage and the size of the transferred data is significant. So, I tried to set&amp;nbsp;MCUMGR_GRP_SETTINGS_BUFFER_TYPE_HEAP=y but got &amp;#39;n&amp;#39; due to the dependency of the heap size which is 0&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Here is the dependency from Kconfig:&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;config MCUMGR_GRP_SETTINGS_BUFFER_TYPE_HEAP
bool &amp;quot;Heap (dynamic size)&amp;quot;
depends on COMMON_LIBC_MALLOC_ARENA_SIZE &amp;gt; 0
help
Use dynamic heap memory allocation through malloc, if there is
insufficient heap memory for the allocation then the request will be
rejected.&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;What could be the solution for this issue?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two simultaneous heaps combining: kernel heap and libc heap</title><link>https://devzone.nordicsemi.com/thread/565270?ContentTypeID=1</link><pubDate>Wed, 22 Apr 2026 03:45:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ddf57ed7-4cdf-4d6d-8e3f-9981d9b54267</guid><dc:creator>Justin012</dc:creator><description>&lt;p data-start="0" data-end="8"&gt;Hi Egor,&lt;/p&gt;
&lt;p data-start="10" data-end="127"&gt;you&amp;rsquo;re right &amp;mdash; having two heaps is not ideal, and unfortunately there&amp;rsquo;s no built-in way to truly merge them into one.&lt;/p&gt;
&lt;p data-start="129" data-end="212"&gt;&lt;strong data-start="129" data-end="160"&gt;Simple approach that works:&lt;/strong&gt;&lt;br /&gt;&amp;nbsp;Redirect everything to the Zephyr (kernel) heap. &lt;span style="color:#ffffff;"&gt;&lt;a style="color:#ffffff;" href="https://heardleonline.io/"&gt;heardle game&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p data-start="214" data-end="225"&gt;That means:&lt;/p&gt;
&lt;ul data-start="226" data-end="346"&gt;
&lt;li data-section-id="ae90fk" data-start="226" data-end="274"&gt;Override &lt;code data-start="237" data-end="245"&gt;malloc&lt;/code&gt;, &lt;code data-start="247" data-end="253"&gt;free&lt;/code&gt;, &lt;code data-start="255" data-end="263"&gt;calloc&lt;/code&gt;, &lt;code data-start="265" data-end="274"&gt;realloc&lt;/code&gt;&lt;/li&gt;
&lt;li data-section-id="l6xy9h" data-start="275" data-end="306"&gt;Override C++ &lt;code data-start="290" data-end="295"&gt;new&lt;/code&gt; / &lt;code data-start="298" data-end="306"&gt;delete&lt;/code&gt;&lt;/li&gt;
&lt;li data-section-id="1x6b5fn" data-start="307" data-end="346"&gt;Internally call &lt;code data-start="325" data-end="335"&gt;k_malloc&lt;/code&gt; / &lt;code data-start="338" data-end="346"&gt;k_free&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-start="348" data-end="436"&gt;This way you effectively use &lt;strong data-start="377" data-end="394"&gt;one heap only&lt;/strong&gt;, and you can monitor it with Zephyr APIs.&lt;/p&gt;
&lt;p data-start="438" data-end="454"&gt;Also, I&amp;rsquo;d avoid:&lt;/p&gt;
&lt;div class="relative w-full mt-4 mb-1"&gt;
&lt;div class=""&gt;
&lt;div class="relative"&gt;
&lt;div class="h-full min-h-0 min-w-0"&gt;
&lt;div class="h-full min-h-0 min-w-0"&gt;
&lt;div class="border border-token-border-light border-radius-3xl corner-superellipse/1.1 rounded-3xl"&gt;
&lt;div class="h-full w-full border-radius-3xl bg-token-bg-elevated-secondary corner-superellipse/1.1 overflow-clip rounded-3xl lxnfua_clipPathFallback"&gt;
&lt;div class="pointer-events-none absolute end-1.5 top-1 z-2 md:end-2 md:top-1"&gt;&lt;/div&gt;
&lt;div class="relative"&gt;
&lt;div class="pe-11 pt-3"&gt;
&lt;div class="relative z-0 flex max-w-full"&gt;
&lt;div id="code-block-viewer" dir="ltr"&gt;
&lt;div class="cm-scroller"&gt;
&lt;div class="cm-content q9tKkq_readonly"&gt;&lt;span&gt;COMMON_LIBC_MALLOC_ARENA_SIZE = -1&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=""&gt;
&lt;div class=""&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p data-start="498" data-end="595"&gt;Better set a fixed size or fully redirect allocations, otherwise memory usage is hard to control.&lt;/p&gt;
&lt;p data-start="597" data-end="737"&gt;&lt;strong data-start="597" data-end="610"&gt;In short:&lt;/strong&gt;&lt;br data-start="610" data-end="613" /&gt; You can&amp;rsquo;t truly combine both heaps, but you can &lt;strong data-start="661" data-end="704"&gt;force everything to use the kernel heap&lt;/strong&gt;, which is the cleanest solution.&lt;/p&gt;
&lt;p data-start="739" data-end="757" data-is-last-node="" data-is-only-node=""&gt;Hope that helps&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>