Symbian3/SDK/Source/GUID-239AA6F5-30CE-5FF0-9C36-93D39FECE1DD.dita
changeset 7 51a74ef9ed63
parent 0 89d6a7a84779
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 concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-239AA6F5-30CE-5FF0-9C36-93D39FECE1DD" xml:lang="en"><title>How
       
    13 to switch heaps</title><shortdesc>After a call to <codeph>User::SwitchHeap()</codeph>, any new request
       
    14 for memory is satisfied from the new heap.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    15 <p>A thread can switch between heaps using <codeph>User::SwitchHeap()</codeph>. </p>
       
    16 <p>After a call to this function, any new request for memory is satisfied
       
    17 from the new heap.</p>
       
    18 <p>When freeing memory, it is <b>extremely important</b> that the current
       
    19 heap is the heap from which it was allocated. Trying to free a memory cell
       
    20 from a heap when it was allocated from a different heap has undefined consequences.</p>
       
    21 <codeblock id="GUID-8265D4CF-CDCE-51EF-AC31-765830961D8E" xml:space="preserve">Thing* mything = new Thing;                // Allocate on current heap
       
    22 RHeap* oldHeap = User::SwitchHeap(newHeap);// Change heaps
       
    23 ...                                        // Use new heap
       
    24 User::SwitchHeap(oldHeap);                 // Change to old heap
       
    25 delete mything;                            // before deleting.</codeblock>
       
    26 </conbody></concept>