Symbian3/SDK/Source/GUID-C4C8395E-F982-4D6A-88D3-28EDC494817F.dita
changeset 7 51a74ef9ed63
child 8 ae94777fff8f
equal deleted inserted replaced
6:43e37759235e 7:51a74ef9ed63
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE task
       
    11   PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
       
    12 <task id="GUID-C4C8395E-F982-4D6A-88D3-28EDC494817F" xml:lang="en"><title>Requesting
       
    13 RAM Asynchronously</title><shortdesc>This section describes how an application can request for free
       
    14 RAM asynchronously.</shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
       
    15 <prereq id="GUID-6C258B11-CE78-42F2-828D-E9C68598C193"><p>Perform the steps
       
    16 described in <xref href="GUID-50CA5439-29A1-426C-83BA-EC048FE86CDE.dita">Allowing
       
    17 Large Memory Allocation</xref>.</p></prereq>
       
    18 <context id="GUID-D36C0590-A436-458B-B7A6-F2E8577E26C6">       <p>Requesting
       
    19 free RAM asynchronously is recommended as the application is not blocked during
       
    20 the method call handling.</p>     </context>
       
    21 <steps id="GUID-4DD07DEC-6017-4237-BE46-1D69E5FBD744-GENID-1-8-1-10-1-1-8-1-5-1-6-1-6-1-5-1-3-3">
       
    22 <step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-8-1-10-1-1-8-1-5-1-6-1-6-1-5-1-3-3-1"><cmd>Start an asynchronous
       
    23 request for a block of memory.</cmd>
       
    24 <info><codeblock xml:space="preserve">CMemoryAllocatingObject::StartFunctionalityRequiringAllocationL()
       
    25     {
       
    26     User::LeaveIfError(iOomMonitorSession.Connect());
       
    27     iMemoryRequester = CMemoryRequester::NewL(iOomMonitorSession, *this);
       
    28     iMemoryRequester-&gt;Start(KLargeValueToAllocate);
       
    29     }
       
    30 </codeblock></info>
       
    31 </step>
       
    32 <step id="GUID-9A69E5AD-E938-4092-A8C2-CB65C37C8962-GENID-1-8-1-10-1-1-8-1-5-1-6-1-6-1-5-1-3-3-2"><cmd>Implement the active
       
    33 object and request for free memory.</cmd>
       
    34 <info><codeblock xml:space="preserve">void CMemoryRequester::Start(TInt aBytesRequested)
       
    35     {
       
    36     iOomMonitorSession.RequestFreeMemory(aBytesRequested, iStatus);    
       
    37     SetActive();
       
    38     }
       
    39 </codeblock></info>
       
    40 </step>
       
    41 </steps>
       
    42 <example><p>The following code snippet illustrates an asynchronous request
       
    43 for free RAM allocation: </p><codeblock xml:space="preserve">const TInt KLargeValueToAllocate = 2097152; //2MB
       
    44 
       
    45 // Start an asynchronous request for block of memory
       
    46 CMemoryAllocatingObject::StartFunctionalityRequiringAllocationL()
       
    47     {
       
    48     User::LeaveIfError(iOomMonitorSession.Connect());
       
    49     iMemoryRequester = CMemoryRequester::NewL(iOomMonitorSession, *this);
       
    50     iMemoryRequester-&gt;Start(KLargeValueToAllocate);
       
    51     }
       
    52 
       
    53 // Called when the asynchronous request is completed
       
    54 CMemoryAllocatingObject::MemoryRequestCompleteL(TInt aResult)
       
    55     {
       
    56     if (aResult == KErrNone)
       
    57         {
       
    58         DoFunctionRequiring_KLargeValueToAllocate_BytesL();
       
    59         }
       
    60     iOomMonitorSession.Close();
       
    61     }
       
    62 The active object implementation is the following:
       
    63 
       
    64 // Start an asynchronous request for block of memory
       
    65 void CMemoryRequester::Start(TInt aBytesRequested)
       
    66     {
       
    67     iOomMonitorSession.RequestFreeMemory(aBytesRequested, iStatus);    
       
    68     SetActive();
       
    69     }
       
    70     
       
    71 
       
    72 // Called when the asynchronous request is completed
       
    73 void CMemoryRequester::RunL()
       
    74     {
       
    75     iObserver.MemoryRequestCompleteL(iStatus.Int());
       
    76     }
       
    77 </codeblock></example>
       
    78 </taskbody><related-links>
       
    79 <link href="GUID-CE308C71-D8B2-43B3-97FD-B868285ED5FB.dita"><linktext>OOM Monitor
       
    80 Priority</linktext></link>
       
    81 <link href="GUID-39A8FBC9-5FD6-4F92-B71E-5C5438ECFD46.dita"><linktext>OOM Monitor
       
    82 Overview</linktext></link>
       
    83 <link href="GUID-88752800-83BD-4845-80A0-6B65D8D81924.dita"><linktext>OOM Monitor
       
    84 Reference</linktext></link>
       
    85 </related-links></task>