Week 23 contribution of PDK documentation content. See release notes for details. Fixes bugs Bug 2714, Bug 462.
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --><!-- This component and the accompanying materials are made available under the terms of the License "Eclipse Public License v1.0" which accompanies this distribution, and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --><!-- Initial Contributors: Nokia Corporation - initial contribution.Contributors: --><!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"><task id="GUID-C4C8395E-F982-4D6A-88D3-28EDC494817F" xml:lang="en"><title>RequestingRAM Asynchronously</title><shortdesc>This section describes how an application can request for freeRAM asynchronously.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody><prereq id="GUID-6C258B11-CE78-42F2-828D-E9C68598C193"><p>Perform the stepsdescribed in <xref href="GUID-50CA5439-29A1-426C-83BA-EC048FE86CDE.dita">AllowingLarge Memory Allocation</xref>.</p></prereq><context id="GUID-D36C0590-A436-458B-B7A6-F2E8577E26C6"> <p>Requestingfree RAM asynchronously is recommended as the application is not blocked duringthe method call handling.</p> </context><steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-12-1-12-1-1-9-1-5-1-6-1-6-1-5-1-3-3"><step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-12-1-12-1-1-9-1-5-1-6-1-6-1-5-1-3-3-1"><cmd>Start an asynchronousrequest for a block of memory.</cmd><info><codeblock xml:space="preserve">CMemoryAllocatingObject::StartFunctionalityRequiringAllocationL() { User::LeaveIfError(iOomMonitorSession.Connect()); iMemoryRequester = CMemoryRequester::NewL(iOomMonitorSession, *this); iMemoryRequester->Start(KLargeValueToAllocate); }</codeblock></info></step><step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-12-1-12-1-1-9-1-5-1-6-1-6-1-5-1-3-3-2"><cmd>Implement the activeobject and request for free memory.</cmd><info><codeblock xml:space="preserve">void CMemoryRequester::Start(TInt aBytesRequested) { iOomMonitorSession.RequestFreeMemory(aBytesRequested, iStatus); SetActive(); }</codeblock></info></step></steps><example><p>The following code snippet illustrates an asynchronous requestfor free RAM allocation: </p><codeblock xml:space="preserve">const TInt KLargeValueToAllocate = 2097152; //2MB// Start an asynchronous request for block of memoryCMemoryAllocatingObject::StartFunctionalityRequiringAllocationL() { User::LeaveIfError(iOomMonitorSession.Connect()); iMemoryRequester = CMemoryRequester::NewL(iOomMonitorSession, *this); iMemoryRequester->Start(KLargeValueToAllocate); }// Called when the asynchronous request is completedCMemoryAllocatingObject::MemoryRequestCompleteL(TInt aResult) { if (aResult == KErrNone) { DoFunctionRequiring_KLargeValueToAllocate_BytesL(); } iOomMonitorSession.Close(); }The active object implementation is the following:// Start an asynchronous request for block of memoryvoid CMemoryRequester::Start(TInt aBytesRequested) { iOomMonitorSession.RequestFreeMemory(aBytesRequested, iStatus); SetActive(); }// Called when the asynchronous request is completedvoid CMemoryRequester::RunL() { iObserver.MemoryRequestCompleteL(iStatus.Int()); }</codeblock></example></taskbody><related-links><link href="GUID-CE308C71-D8B2-43B3-97FD-B868285ED5FB.dita"><linktext>OOM MonitorPriority</linktext></link><link href="GUID-39A8FBC9-5FD6-4F92-B71E-5C5438ECFD46.dita"><linktext>OOM MonitorOverview</linktext></link><link href="GUID-88752800-83BD-4845-80A0-6B65D8D81924.dita"><linktext>OOM MonitorReference</linktext></link></related-links></task>