×
Namespaces

Variants
Actions

Compressing heap memory on Symbian

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95
CompatibilityArticle
Keywords: Heap
Created: User:Nokia Developer KB (03 Apr 2009)
Last edited: hamishwillee (20 Aug 2012)

Contents

Overview

The CompressAllHeaps() method reclaims any available pages at the top of each user heap. It does not attempt heap defragmentation and ignores locked heaps, so it is very efficient.

Description

The amount of memory given back to the system following a call to User::CompressAllHeaps can vary a lot, is quite unpredictable, and does not work in some cases.

Check the code snippet where memory allocation (User::Alloc() method) has been done and immediately compressed using the CompressAllHeaps and Heap().Compress() methods. The logs indicate that the free RAM size has increased. This function works fine only when there is free RAM on top of each user heap.

Solution

The following code snippet shows how to use the CompressAllHeaps functionality.

  //sample code
TInt retval;
TInt retval1;
TInt ibeforeFreeRAM;
TInt iafterFreeRAM;
TInt iafterFreeRAMCompress;
User::Alloc(882688);
HAL::Get(HAL::EMemoryRAMFree, ibeforeFreeRAM);
TBuf<50> temp;
TBuf<50> temp1;
TBuf<50> temp2;
DebugLog(_L("ibeforeFreeRAM "));
DebugLog(_L(""));
temp.AppendNum(ibeforeFreeRAM);
DebugLog(temp);
retval=User::CompressAllHeaps(); //using CompressAllHeaps method
HAL::Get(HAL::EMemoryRAMFree, iafterFreeRAM);
DebugLog(_L("iafterFreeRAM"));
DebugLog(_L(""));
temp1.AppendNum(iafterFreeRAM);
DebugLog(temp1);
User::Heap().Compress(); //using Heap Compress method
HAL::Get(HAL::EMemoryRAMFree, iafterFreeRAMCompress);
DebugLog(_L("iafterFreeRAM : Compress"));
DebugLog(_L(""));
temp2.AppendNum(iafterFreeRAMCompress);
DebugLog(temp2);
 
 
Output sample:
ibeforeFreeRAM 23875584
iafterFreeRAM 24113152
iafterFreeRAM : Compress 24113152


Related articles

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 20 August 2012, at 02:53.
64 page views in the last 30 days.
×