<?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 - Simulating LowMem (low memory stress tool) on the emulator - Comments</title>
 <link>http://www.newlc.com/topic-17152</link>
 <description>Comments for &quot;Simulating LowMem (low memory stress tool) on the emulator&quot;</description>
 <language>en</language>
<item>
 <title>Re: Simulating LowMem (low memory stress tool) on the emulator</title>
 <link>http://www.newlc.com/topic-17152#comment-36521</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;You shouldn&amp;#039;t get an access violation (although you will, if the framework code runs out of memory).&lt;br /&gt;&lt;br /&gt;Your app should exit with -4 if it runs out of memory and can&amp;#039;t recover. I couldn&amp;#039;t actually run my app on the 3rd edition satisfactorily, since the framework code crashes so easily, so you&amp;#039;ll have to investigate how to properly propagate the error yourself.&lt;/div&gt;</description>
 <pubDate>Mon, 08 Jan 2007 08:42:45 +0100</pubDate>
 <dc:creator>mikaraento</dc:creator>
 <guid isPermaLink="false">comment 36521 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Simulating LowMem (low memory stress tool) on the emulator</title>
 <link>http://www.newlc.com/topic-17152#comment-36520</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Thanks for the great advice! I have an exciting program which simulates the LowMem app on the emulator now.&amp;nbsp; (Sometimes you can see when something fails within their code due to low memory, but which would normally work perfectly given enough memory... looks like at least the emulator version of the OS needs some better error handling!)&lt;br /&gt;&lt;br /&gt;There&amp;#039;s only one thing, though.&amp;nbsp; With the actual LowMem app given by Symbian, when the app runs out of memory and a message box appears saying &amp;quot;Out of memory&amp;quot;, the LowMem app steals back the focus and asks you if you want to continue the test.&amp;nbsp; So, obviously the LowMem app is aware when the thread has run out of memory.&amp;nbsp; LowMem will close down the app (I can see my destructors being called on the device because of log files).&lt;br /&gt;&lt;br /&gt;My app in particular is tricky because there is an APP and a LIB, and also the LIB uses networking.&amp;nbsp; It seems as if both the GUI code in the APP, and the networking code in the LIB are running out simultaneously (they&amp;#039;re active objects after all).&lt;br /&gt;&lt;br /&gt;Well, the exception handling of RThread probably doesn&amp;#039;t work on the emulator (because windows always catches things like access violations).&amp;nbsp; At least, I tried it.&amp;nbsp; So, in my version of the LowMem tool I run the threads as an active object, with another timer active object in the background.&amp;nbsp; If the thread hasn&amp;#039;t ended normally after 15 seconds, the timer shuts it down with either a RThread::Kill() or a RThread::Terminate() call.&amp;nbsp; (I&amp;#039;ve tried them both, they both seem to do exactly the same thing)&lt;br /&gt;&lt;br /&gt;The problem is, RThread::Kill and Terminate immediately stop the thread... no destructors are called.&amp;nbsp; Does anyone have any idea how LowMem does it?&amp;nbsp; i.e. forces the app to shut down when you tell it to continue the test?&amp;nbsp; Because that&amp;#039;s where my app is causing KERN-EXEC 3 errors on the device.&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;-euroq&lt;/div&gt;</description>
 <pubDate>Thu, 04 Jan 2007 22:11:19 +0100</pubDate>
 <dc:creator>euroq</dc:creator>
 <guid isPermaLink="false">comment 36520 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Simulating LowMem (low memory stress tool) on the emulator</title>
 <link>http://www.newlc.com/topic-17152#comment-36519</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;The correct way is to spawn a thread to run the application in. When creating the thread, you specify the maximum heap. &lt;br /&gt;&lt;br /&gt;On 9.1, you have to add support code to your application&amp;#039;s E32Main. I do it like:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;// in the tester&lt;br /&gt;RChunk heapc;&lt;br /&gt;User::LeaveIfError(heapc.CreateGlobal(KHeapName, 20, 20));&lt;br /&gt;CleanupClosePushL(heapc); pushed++;&lt;br /&gt;TInt *heapp=(TInt*)heapc.Base();&lt;br /&gt;*heapp=iCurrentMaxHeapSize;&lt;br /&gt;RProcess thread;&lt;br /&gt;TInt err=thread.Create(KExeName, KNullDesC);&lt;br /&gt;&lt;br /&gt;// in the app&lt;br /&gt;TInt RunApplication(TAny*)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return EikStart::RunApplication(NewApplication);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;GLDEF_C TInt E32Main()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; RChunk heapc;&lt;br /&gt;&amp;nbsp; &amp;nbsp; TInt err=heapc.OpenGlobal(_L(&amp;quot;contextcontacts_heap&amp;quot;), ETrue);&lt;br /&gt;&amp;nbsp; &amp;nbsp; if (err!=KErrNone) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return EikStart::RunApplication(NewApplication);&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RThread thread;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TInt heap=*(TInt*)heapc.Base();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; heapc.Close();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; err=thread.Create(_L(&amp;quot;contextcontacts2&amp;quot;),&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;RunApplication, // thread&amp;#039;s main function&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20*1024, /* stack */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; heap, /* min heap */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; heap, /* max heap */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EOwnerProcess);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (err!=KErrNone) return err;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; thread.SetPriority(EPriorityNormal);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TRequestStatus s;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; thread.Logon(s);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; thread.Resume();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; User::WaitForRequest(s);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TExitCategoryName n=thread.ExitCategory();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TInt reason=thread.ExitReason();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TExitType exittype=thread.ExitType();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; thread.Close();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (exittype==EExitPanic) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RDebug::Print( n );&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; User::Panic( n, reason);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return reason;&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;On pre-9.1, you can fully encapsulate the code in the tester:&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;void run_app_inner()&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TInt pushed=0;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TFileName fn=_L(&amp;quot;z:\\system\\apps\\context_log\\context_log.app&amp;quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CApaCommandLine* cmd=CApaCommandLine::NewL(fn);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* RunAppInsideThread deletes the command line */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EikDll::RunAppInsideThread(cmd);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CleanupStack::PopAndDestroy(pushed);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;TInt run_app(TAny*)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CTrapCleanup* cleanupStack = CTrapCleanup::New();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TRAPD(err, run_app_inner());&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; delete cleanupStack;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return err;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// and then&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RThread thread;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TInt err=thread.Create(_L(&amp;quot;context_log&amp;quot;),&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;run_app, // thread&amp;#039;s main function&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20*1024, /* stack */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,&amp;nbsp; // parameters&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NULL,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; heap, /* min heap */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; heap, /* max heap */&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EOwnerProcess);&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;On both you then follow in the tester with:&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; User::LeaveIfError(err);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; thread.SetPriority(EPriorityNormal);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TRequestStatus s;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; thread.Logon(s);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; thread.Resume();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; User::WaitForRequest(s);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; msg=_L8(&amp;quot; done: &amp;quot;);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; msg.Append(thread.ExitCategory());&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; msg.Append(_L8(&amp;quot; &amp;quot;));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; msg.AppendNum(thread.ExitReason());&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; msg.Append(_L8(&amp;quot;\n&amp;quot;));&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;That&amp;#039;s the basic idea.&lt;/div&gt;</description>
 <pubDate>Thu, 21 Dec 2006 15:05:16 +0100</pubDate>
 <dc:creator>mikaraento</dc:creator>
 <guid isPermaLink="false">comment 36519 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Simulating LowMem (low memory stress tool) on the emulator</title>
 <link>http://www.newlc.com/topic-17152#comment-36518</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Havn&amp;#039;t used these functions, but from reading the documentation, maybe the problem is it gives the _current_ max, not counting in that your heap may expand.&lt;br /&gt;&lt;br /&gt;A thread has a min and a max limit for its heap, when the thread is started, it gets the min size of the heap, and if a call to alloc doesn&amp;#039;t fit, it will expand it, in increments, until it hits the max limit.&lt;br /&gt;&lt;br /&gt;So if it hasn&amp;#039;t expanded yet when you call that function, and then the next allocation will make it expand, you would get the result you are experiencing.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Thu, 21 Dec 2006 14:24:58 +0100</pubDate>
 <dc:creator>alh</dc:creator>
 <guid isPermaLink="false">comment 36518 at http://www.newlc.com</guid>
</item>
<item>
 <title>Simulating LowMem (low memory stress tool) on the emulator</title>
 <link>http://www.newlc.com/topic-17152</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/topic-17152&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/topic-17152#comments</comments>
 <category domain="http://www.newlc.com/forums/symbian-c">Symbian C++</category>
 <pubDate>Wed, 20 Dec 2006 23:10:56 +0100</pubDate>
 <dc:creator>euroq</dc:creator>
 <guid isPermaLink="false">16703 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
