Compressing heap memory on Symbian
Article Metadata
Tested with
Devices(s): Nokia N95
Compatibility
Platform(s): S60 3rd Edition and later
Article
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


(no comments yet)