<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - how to measure free RAM - Comments</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram</link>
 <description>Comments for &quot;how to measure free RAM&quot;</description>
 <language>en</language>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46382</link>
 <description>&lt;p&gt;malloc will &quot;under the hood&quot; result in a call to User::Alloc, since that is the native symbian API for memory allocation, so this will work for that too.&lt;/p&gt;

&lt;p&gt;&lt;pre class=&quot;bb-code-block&quot;&gt;
TInt numbytesonheap = 0;
TInt cellscount = User::AllocSize(numbytesonheap);
TInt biggestblock = 0;
TInt available = User::Available(biggestblock);
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;&quot;numbytesonheap&quot; would be the total sum of bytes allocated in all calls to malloc.&lt;/p&gt;

&lt;p&gt;&quot;numbytesonheap + available&quot; would be an approximate size of the heap chunk, but a more exact number can be got through:&lt;br /&gt;
&lt;pre class=&quot;bb-code-block&quot;&gt;
User::Heap()-&amp;gt;Size();
&lt;/pre&gt;&lt;br /&gt;
This is the number of bytes actually allocated to your program at this point, &quot;numbytesonheap&quot; is just how many bytes currently in use.&lt;/p&gt;

&lt;p&gt;&quot;biggestblock&quot; is the biggest continuous block in the heap. If you try to allocate a bigger block then this in one call, then the heap will have to try to grow, even if there is more bytes &quot;available&quot;.&lt;/p&gt;

&lt;p&gt;If &quot;biggestblock&quot; is a lot smaller then &quot;available&quot; that could mean heap fragmentation caused by bad ordering of your malloc and free-calls, creating lots of small &quot;holes&quot; in the heap, and therefore make your program use more memory then it really needs. &lt;/p&gt;

&lt;p&gt;Its important to remember that &quot;available&quot; is just the number of bytes currently available _without_heap_resizing_.  The heap will automatically grow  when you try to allocate more then &quot;available&quot;, until it reaches its max size.&lt;br /&gt;
&lt;/p&gt;</description>
 <pubDate>Fri, 16 May 2008 10:13:56 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46382 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46367</link>
 <description>&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;br /&gt;
Tint User::AllocSize(TInt &amp;aTotalAllocSize) will return in the argument, the total number of bytes in your heap at this point.&lt;br /&gt;
add it to User::Available() and you will see how big your heap chunk is currently.&lt;br /&gt;
&lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Thanks alot alh. I got the stacksize calculation but not sure about heap. Does this mean that I have to use User:Alloc in stead of all the malloc() i&#039;m currently using in order to be able to measure current heap size?&lt;/p&gt;

&lt;p&gt;I searched the docs on User::AllocSize and User::Available but not much info. Can you, if possible give me a sample code? My dll has lots &amp; lots of malloc and memcpy  and all that...&lt;/p&gt;

&lt;p&gt;Thanks a gain&lt;/p&gt;</description>
 <pubDate>Thu, 15 May 2008 11:34:12 +0200</pubDate>
 <dc:creator>coolclu3</dc:creator>
 <guid isPermaLink="false">comment 46367 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46359</link>
 <description>&lt;p&gt;&lt;div class=&quot;bb-quote&quot;&gt;&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;br /&gt;
I simply want to moniter how much memory my program has used (including mainly heap + stack size and all that) at a few points&lt;br /&gt;
&lt;/blockquote&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Oh, why didn&#039;t you say so from the start? &lt;img src=&quot;/sites/all/modules/smileys/packs/example/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Tint User::AllocSize(TInt &amp;aTotalAllocSize)  will return in the argument, the total number of bytes in your heap at this point.&lt;br /&gt;
add it to User::Available() and you will see how big your heap chunk is currently.&lt;/p&gt;

&lt;p&gt;To measure stack usage, you can save a pointer to a stack variable in the very  begininig of your program, and then compare this to a pointer of any stack variable later.&lt;br /&gt;
along these lines:&lt;/p&gt;

&lt;p&gt;&lt;pre class=&quot;bb-code-block&quot;&gt;
TInt gStackAddress;

TInt E32Main()
{
TInt firststackpos;
gStackAddress = (TInt)&amp;firststackpos;

// [...] Rest of entrypoint function
}

TInt GetBytesOnStack()
{
 TInt dummy;
 return gStackAddress - (TInt)&amp;dummy;
}
&lt;/pre&gt;&lt;/p&gt;</description>
 <pubDate>Thu, 15 May 2008 09:13:23 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46359 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46336</link>
 <description>&lt;p&gt;Duplicate post&lt;/p&gt;</description>
 <pubDate>Wed, 14 May 2008 08:52:41 +0200</pubDate>
 <dc:creator>coolclu3</dc:creator>
 <guid isPermaLink="false">comment 46336 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46338</link>
 <description>&lt;p&gt;Thanks alh for your advice, but it&#039;s not what i want yet.&lt;/p&gt;

&lt;p&gt;I simply want to moniter how much memory my program has used (including mainly heap + stack size and all that) at a few points during execution. I used to think this shouldn&#039;t be so complicated for such an advanced OS...........Why why why&lt;/p&gt;</description>
 <pubDate>Wed, 14 May 2008 08:48:59 +0200</pubDate>
 <dc:creator>coolclu3</dc:creator>
 <guid isPermaLink="false">comment 46338 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46329</link>
 <description>&lt;p&gt;No. &lt;br /&gt;
It just means you have that number of bytes currently free on your current threads heap.&lt;/p&gt;

&lt;p&gt;It does NOT even mean that an allocation for a bigger block then &quot;avaialable&quot; will fail, because your heap migh expand, if you have specified that it is allowed to.&lt;/p&gt;

&lt;p&gt;As I wrote in my previous post, you can change heapsize either in the mmp file with EPOCHEAPSIZE, or by useing the code I posted...&lt;/p&gt;

&lt;p&gt;you WILL have to change heap size if you are to allocate things as big as 20MB.&lt;/p&gt;

&lt;p&gt;easiest way to know if there is room enough in RAM for a heap with 20MB of space is probably to try create one as described in my previous post.&lt;/p&gt;

&lt;p&gt;put minsize to 20MB and if there is space enough for it, it will be created, if not, it will fail, and you will have to try find some other phone to run on, or optimize ram usage.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Tue, 13 May 2008 12:27:20 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46329 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46322</link>
 <description>&lt;p&gt;Thank you all, &lt;br /&gt;
Sorry to bring up this topic again. Been away for a short while.&lt;/p&gt;

&lt;p&gt;I have followed the thread that rbrunner suggested and found User::Available(TInt &amp;a).&lt;br /&gt;
In the document it says: Returns &quot;The total free space currently available on the current thread&#039;s heap.&quot;&lt;/p&gt;

&lt;p&gt;I have User:Available() to be 316964 at some point. Does thi mean that I have 316964 BYTES(or what) available free RAM at that time?&lt;br /&gt;
thanks again&lt;/p&gt;</description>
 <pubDate>Tue, 13 May 2008 09:50:17 +0200</pubDate>
 <dc:creator>coolclu3</dc:creator>
 <guid isPermaLink="false">comment 46322 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46060</link>
 <description>&lt;p&gt;kern-exec 3 is quite common when porting stuff that takes a lot of memory.&lt;/p&gt;

&lt;p&gt;reason is quite simple, a memory allocation fails, and the orginal app doesn&#039;t handle all memory allocation problems, so a pointer ends up being null.&lt;br /&gt;
then someone (for example a memcopy) tries to copy stuff into it, and bam, you panic with kern-exec 3.&lt;/p&gt;

&lt;p&gt;If your app needs 20MB of memory, you will have to increase the default heap size in your application.&lt;/p&gt;

&lt;p&gt;You are supposed to be able to do this by specifying the EPOCHEAPSIZE keyword in your mmp-file, but if that doesn&#039;t work for you, then you can try add this in your E32Main:&lt;/p&gt;

&lt;p&gt;TInt E32Main()&lt;br /&gt;
	{&lt;br /&gt;
	RHeap* newheap = User::ChunkHeap(NULL,300000,25000000);  //smallest size 300Kb, grow to 25 MB&lt;br /&gt;
	RHeap* oldheap = NULL;&lt;br /&gt;
	if(newheap) &lt;br /&gt;
		{&lt;br /&gt;
		oldheap = User::SwitchHeap(newheap);&lt;br /&gt;
		}&lt;br /&gt;
	return EikStart::RunApplication(NewApplication);&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;Be adviced though that 20MB is _very_much_ for a phone application, and you might have trouble finding a phone it runs on at all.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description>
 <pubDate>Mon, 28 Apr 2008 17:17:28 +0200</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 46060 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46039</link>
 <description>&lt;p&gt;Well, correct me if I am wrong - but memcpy does not allocate any memory, it just copies it, right? I don&#039;t see how memory could get full at the execution of a memcpy, then. Are you sure your pointers are ok, and enough destination memory allocated?&lt;/p&gt;

&lt;p&gt;Anyway, a quick use of forum search (box top right) for &quot;free memory amount&quot; gave me the following:&lt;br /&gt;
&lt;a href=&quot;http://www.newlc.com/topic-3151&quot; class=&quot;bb-url&quot;&gt;http://www.newlc.com/topic-3151&lt;/a&gt;&lt;/p&gt;</description>
 <pubDate>Sun, 27 Apr 2008 10:24:39 +0200</pubDate>
 <dc:creator>rbrunner</dc:creator>
 <guid isPermaLink="false">comment 46039 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46038</link>
 <description>&lt;p&gt;Hi rbrunner,&lt;br /&gt;
First of all, I know that my app would takes lots of memory, coz I&#039;m porting one PC application, which takes something like 20M on PC.&lt;br /&gt;
Anyway, it dies at a memcpy function, which is within my library. I can&#039;t find any other clue than guessing that it&#039;s full memory.&lt;br /&gt;
Cheers&lt;/p&gt;</description>
 <pubDate>Sun, 27 Apr 2008 09:34:13 +0200</pubDate>
 <dc:creator>coolclu3</dc:creator>
 <guid isPermaLink="false">comment 46038 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram#comment-46037</link>
 <description>&lt;p&gt;What makes you think that filling up all available memory is the reason for your problem? A &quot;kern-exec 3&quot; can have many different reasons.&lt;/p&gt;

&lt;p&gt;Did you already debug and check where the error occurs? (Not with some kind of &quot;memory debugger&quot;, as you asked, but with the &quot;normal&quot; runtime debugger.)&lt;/p&gt;</description>
 <pubDate>Sun, 27 Apr 2008 07:33:44 +0200</pubDate>
 <dc:creator>rbrunner</dc:creator>
 <guid isPermaLink="false">comment 46037 at http://www.newlc.com</guid>
</item>
<item>
 <title>how to measure free RAM</title>
 <link>http://www.newlc.com/forum/how-measure-free-ram</link>
 <description>&lt;p&gt;Hi all&lt;br /&gt;
I am pretty new to Symbian. So please ignore if this is too simple a quetsion. I&#039;ve googled and read docs, but not yet found the answer&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/forum/how-measure-free-ram&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/forum/how-measure-free-ram#comments</comments>
 <category domain="http://www.newlc.com/forums/symbian-c">Symbian C++</category>
 <pubDate>Sat, 26 Apr 2008 20:09:33 +0200</pubDate>
 <dc:creator>coolclu3</dc:creator>
 <guid isPermaLink="false">20813 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
