This section describes how an application can request for free RAM asynchronously.
Perform the steps described in Allowing Large Memory Allocation .
Requesting free RAM asynchronously is recommended as the application is not blocked during the method call handling.
The following code snippet illustrates an asynchronous request for free RAM allocation:
const TInt KLargeValueToAllocate = 2097152; //2MB // Start an asynchronous request for block of memory CMemoryAllocatingObject::StartFunctionalityRequiringAllocationL() { User::LeaveIfError(iOomMonitorSession.Connect()); iMemoryRequester = CMemoryRequester::NewL(iOomMonitorSession, *this); iMemoryRequester->Start(KLargeValueToAllocate); } // Called when the asynchronous request is completed CMemoryAllocatingObject::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 memory void CMemoryRequester::Start(TInt aBytesRequested) { iOomMonitorSession.RequestFreeMemory(aBytesRequested, iStatus); SetActive(); } // Called when the asynchronous request is completed void CMemoryRequester::RunL() { iObserver.MemoryRequestCompleteL(iStatus.Int()); }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.