Symbian3/SDK/Source/GUID-239AA6F5-30CE-5FF0-9C36-93D39FECE1DD.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

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