Namespaces
Variants
Actions

Compressing heap memory on Symbian

Jump to: navigation, search
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


Related articles

This page was last modified on 20 August 2012, at 02:53.
185 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved