<?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>Current best dynamic memory allocation method</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82337/current-best-dynamic-memory-allocation-method</link><description>I want to use dynamic memory allocation. After searching these forums, I see the following options: 
 
 malloc 
 k_malloc 
 nrf_malloc 
 balloc 
 
 I haven&amp;#39;t had success with getting any of them to work. I&amp;#39;ve found numerous references to modifying sdk_config</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 06 Dec 2021 12:51:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82337/current-best-dynamic-memory-allocation-method" /><item><title>RE: Current best dynamic memory allocation method</title><link>https://devzone.nordicsemi.com/thread/342063?ContentTypeID=1</link><pubDate>Mon, 06 Dec 2021 12:51:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ef4cd08-1e8d-4888-b6b7-e2531574c7c3</guid><dc:creator>Hakon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]I&amp;#39;ve found numerous references to modifying sdk_config.h, which is not a file I have in my project.[/quote]
&lt;p&gt;This is for when you are building with the nRF5 SDK, not with Zephyr/NCS.&lt;/p&gt;
[quote user="BDA"]Without that stack definition the code seems to just endlessly get stuck in the startup code before it ever branches to main.[/quote]
&lt;p&gt;Can you set CONFIG_RESET_ON_FATAL_ERROR=n and post the serial output log here so I can see what is going wrong? It would be nice if you could share the code as well, or the part of the code that fails.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Current best dynamic memory allocation method</title><link>https://devzone.nordicsemi.com/thread/341755?ContentTypeID=1</link><pubDate>Thu, 02 Dec 2021 19:23:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96854c7c-7557-46a6-8cb3-bca94c679307</guid><dc:creator>BDA</dc:creator><description>&lt;p&gt;After a lot of trial and error I&amp;#39;ve made some progress.&amp;nbsp; I needed to define the stack space as well as the heap in order for it to work with k_malloc.&amp;nbsp; Here is the relevant portion of my current prj.conf:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_HEAP_MEM_POOL_SIZE&lt;/span&gt;&lt;span&gt;=2048&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_MAIN_STACK_SIZE&lt;/span&gt;&lt;span&gt;=16384&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Without that stack definition the code seems to just endlessly get stuck in the startup code before it ever branches to main.&lt;/p&gt;
&lt;p&gt;But, I can&amp;#39;t increase my heap size beyond 2048 or it goes back to failing in the same way as before.&amp;nbsp; This seems similar to &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/72164/config_heap_mem_pool_size-8192-creates-system-reset/297133#297133"&gt;this issue.&lt;/a&gt;&amp;nbsp;&amp;nbsp;This is certainly not right:&amp;nbsp; I&amp;#39;m compiling a test application, and even with that 16k stack and 2k heap I&amp;#39;m&amp;nbsp;only using a tiny portion of the available ram:&lt;/p&gt;
&lt;p&gt;Memory region&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Used Size&amp;nbsp; Region Size&amp;nbsp; %age Used&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FLASH:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;24460 B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 MB&amp;nbsp; &amp;nbsp; &amp;nbsp; 2.33%&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SRAM:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20896 B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;256 KB&amp;nbsp; &amp;nbsp; &amp;nbsp; 7.97%&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can someone&amp;nbsp;help me increase that heap size to more than 2k...?&amp;nbsp; And confirm for me if k_malloc is the recommended way of doing dynamic allocation with a zephyr based project built with 1.7.1?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>