<?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>Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/7311/checking-for-memory-usage-on-runtime</link><description>Hey everyone, 
 I&amp;#39;m having problems with my app&amp;#39;s ram usage as you can see from my previous questions. 
 I&amp;#39;ve tried this little piece of code: 
 void memcheck(void){
	// perform free memory check
	int blockSize = 16;
	int i = 1;
	debug(&amp;quot;Checking</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Jul 2015 07:59:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/7311/checking-for-memory-usage-on-runtime" /><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25866?ContentTypeID=1</link><pubDate>Wed, 22 Jul 2015 07:59:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47384ddf-0e14-4909-b7e6-045c09ea0b50</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;maxpaynner, can you please update this thread&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25863?ContentTypeID=1</link><pubDate>Fri, 29 May 2015 07:23:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e73ae5bb-db0f-4b3a-882d-ec8389ce082e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Cortex M0 does not generate hardfaults for this, this is normal memory corruption.
MPU will allow it, it does not have any checks for HEAP/stack overflow
worst thing is, you&amp;#39;ll most likely grow into your globals as well.
Regarding your question regarding some kind of warning, compilers should be able to figure out that heap memory is over allocated but stack is only runtime so compilers have no way to find that out. I cannot find any standard definition for compiler behavior for this. Maybe someone else can comment on that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25862?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 17:43:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2bdce420-adf8-4608-91b3-89c0e4d42a20</guid><dc:creator>maxpaynner</dc:creator><description>&lt;p&gt;And is it normal for this kind of memory corruption to occur without some kind of warning from the MCU?&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll try that out. Right now I&amp;#39;m cleaning up my code so that I use as little heap memory allocation as possile&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25859?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 17:06:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6615ccc-ee29-4430-a715-359a084a4274</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;app_timers use stack memory buffers and when you do malloc, the library creates more memory per block request to do book keeping.  if heap allocation is affecting app_timers (which does not use heap) then the only reason i can see is that either malloc has moved into stack space or there was no enough stack space for app_timers and they used some heap space.
decreasing heap_size and increasing stack size should solve your problem. Like Dan said you should change also change these in arm_startup_nrf51.s&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25865?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 14:19:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a1fdc25-abad-4a61-b52b-a9f3d0773e64</guid><dc:creator>maxpaynner</dc:creator><description>&lt;p&gt;Hey Dan,&lt;/p&gt;
&lt;p&gt;Thing is I&amp;#39;m using this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;STACK_N_HEAP = -D__HEAP_SIZE=1208 -D__STACK_SIZE=1024
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in my makefile.&lt;/p&gt;
&lt;p&gt;How can the heap grow to 4kb?&lt;/p&gt;
&lt;p&gt;That STACK_N_HEAP flag is added to CFLAGS and ASMFLAGS further down in the makefile&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25861?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 13:48:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b32b8de2-8aab-4c72-b8d4-c4357df45552</guid><dc:creator>maxpaynner</dc:creator><description>&lt;p&gt;I&amp;#39;m using app timers (from app_timer.h) to process data every second. If I use this code, those timers stop working. That&amp;#39;s the problem I&amp;#39;m experiencing, sorry if it was unclear.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25864?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 13:48:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56b68dbc-a5b0-45b2-afdf-b6aff0e5110c</guid><dc:creator>Dan Danknick</dc:creator><description>&lt;p&gt;Just to be clear here, you&amp;#39;re testing the size of the heap space allocated during link time and not exactly the RAM usage of your app. Take a look in the file arm_startup_nrf51.s for your project and the label Heap_Size near the top. It is either set with an EQU statement or assigned a value passed in from the project settings of the build environment.&lt;/p&gt;
&lt;p&gt;I also agree with Aryan that it doesn&amp;#39;t appear your app is &amp;quot;breaking&amp;quot; - you should explain what that means in greater detail.&lt;/p&gt;
&lt;p&gt;Dan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking for memory usage on runtime</title><link>https://devzone.nordicsemi.com/thread/25860?ContentTypeID=1</link><pubDate>Thu, 28 May 2015 10:32:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:746c0902-c156-4cdd-a1c3-664dda7722a9</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;does not look like your application is crashing because of this code. I copy pasted your code and it works fine and no crash. App is still alive. Find out where exactly it crashed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>