<?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>Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14119/circumstances-that-trigger-heap-usage</link><description>Hello, 
 I am developing in NRF51 with gazelle communication. I specify in project setting (in IRAM) to use full RAM of my nRF51, and use MicroLib. My last working application does not use dynamic memory allocation at all, and I verify in produced memory</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 27 May 2016 07:20:57 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14119/circumstances-that-trigger-heap-usage" /><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53963?ContentTypeID=1</link><pubDate>Fri, 27 May 2016 07:20:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62acb085-1579-4e91-930f-8ac57db42c4f</guid><dc:creator>newdev</dc:creator><description>&lt;p&gt;Turns out, this variable-length array is also the one that triggers the heap usage in my code. @RK : I thought the same until I encounter this problem. The odd thing is, I also used this variable-length array in my previous code that does not trigger heap usage at all. So, I am not sure if this variable-length is really the main source of the trigger, maybe the trigger is a product of some combination (with this array). *I use default arm compiler of Keil in c99 mode&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53962?ContentTypeID=1</link><pubDate>Fri, 27 May 2016 00:02:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31677693-e6c9-4de2-9fe1-9199e6661856</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;&amp;quot;I expect the compiler chooses how to implement it,&lt;/p&gt;
&lt;p&gt;you expect wrong then. A local variable like that would always be placed on the stack.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53961?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 22:05:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:877feba3-5a56-4406-bfa3-6a5ee2da0c05</guid><dc:creator>Menno</dc:creator><description>&lt;p&gt;I have had the same problem when I was using a variable sized array inside a function.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int array[variable];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In old C this way of declaring arrays is not even allowed, but in C99 it is allowed. Nevertheless I expect the compiler chooses how to implement it, uses malloc() or place it on the stack (guessing now, but it would be nice if somebody could confirm this). When I replaced in my code the variable with a fixed length which was large enough, space for the heap wasn&amp;#39;t automaticly reserved.
With automaticly reserved I mean that when you are not using any form of dynamic memory allocation, the arm_startup_nrf51 file won&amp;#39;t reserve space for the heap after compiling, which you could verify in the linker file.&lt;/p&gt;
&lt;p&gt;it would be nice if somebody could give some more information about how the variable sized array is handled by the compiler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53957?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 19:45:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad9b6761-462c-4c3a-be82-7cd32c2ee907</guid><dc:creator>John</dc:creator><description>&lt;p&gt;I don&amp;#39;t know of a tool chain that automatically determines you need heap allocated let alone what size it is. It is something you need to specify either by the startup .s file or the IDE. Did you obtain a new version of your startup file that had the heap set to 2K? That&amp;#39;s the only thing I could think of.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53960?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 19:39:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8341384f-70fa-46cd-97a3-54abd0899542</guid><dc:creator>newdev</dc:creator><description>&lt;p&gt;I mean the compiler (or somewhere in sdk, not sure) knows automatically that I don&amp;#39;t use dynamic memory alloc, and set the heap size to 0 automatically. Because my last working version do not use heap at all, even though I did not changed the default linker control file or heap size in IDE. I know it didn&amp;#39;t use heap because I tested this by manually edit linker control file, such that defined or not defined, the heap size always 0, and the map still show startup_nrf51 use 2kB (same size as before editing), which is the full size of stack. So, no heap in those 2kB in the first place.&lt;/p&gt;
&lt;p&gt;About setting the heap size, yes it works for me (succesfully compiled). however, I would like to know what triggers this sudden heap usage, as the behaviour is odd for me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53959?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 19:22:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6dadc35-0d75-47de-9586-99280a5fca7e</guid><dc:creator>John</dc:creator><description>&lt;p&gt;I don&amp;#39;t quite understand what you mean by &amp;quot;heap is automatically set to 0 in compile time&amp;quot;. I&amp;#39;ve seen heap controlled in two ways. One was in the startup .s file such as the one you mention. I&amp;#39;ve also seen the IDE allow you to specify the heap size like IAR does when you edit the linker control file. Is setting the heap size in the startup .s file not working for you? (it sounds like it is)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53958?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 18:44:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0457ecd-c00f-488a-9dce-536aa5df8c06</guid><dc:creator>newdev</dc:creator><description>&lt;p&gt;I add some more information in question about this to make it clearer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Circumstances that trigger Heap usage</title><link>https://devzone.nordicsemi.com/thread/53956?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 17:54:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fecbad9-4aba-42df-8f5f-9cf5700b2b04</guid><dc:creator>John</dc:creator><description>&lt;p&gt;You can set the heap size to 0 if you are not doing dynamic memory allocation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>