Symbian3/SDK/Source/GUID-911CD800-2D1B-5D7B-A67C-66E01F91062C.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-911CD800-2D1B-5D7B-A67C-66E01F91062C" xml:lang="en"><title>Heaps</title><shortdesc>The main thread of a process has a memory chunk that contains the
thread's heap. A program's request for memory is allocated from this heap.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>Each thread has a chunk which contains that thread's program stack. For
the main thread of a process, this chunk also contains the thread's heap.
A program's request for memory is allocated from this heap. For example, a
code fragment such as: </p>
<codeblock id="GUID-ED3A8BC9-7601-5035-B422-ED80E5504867" xml:space="preserve">CArrayFixFlat&lt;...&gt;* fixflat;
...
fixflat = new (ELeave) CArrayFixFlat&lt;...&gt;(3);</codeblock>
<p>causes a portion of memory to be allocated from the heap and its address
returned to the caller. Memory from the heap must be explicitly requested
and, importantly, explicitly freed by the program. </p>
<p>If a process creates additional threads, then a new chunk is created for
each new thread. Each chunk contains the thread's stack; if a new thread is
not sharing an existing heap, then the chunk also contains a new heap. </p>
<p>When a new thread is created, either: </p>
<ul>
<li id="GUID-C915A4D8-70D9-55B4-A16F-9729B1F8D94B"><p>a new heap is created
for it </p> </li>
<li id="GUID-E72B8DF5-CB52-5333-9D3E-EFDBAFE6CB59"><p>it uses the creating
thread's heap </p> </li>
<li id="GUID-20C6F186-6EF6-511E-9291-3273CA930B5D"><p>it uses an explicitly
referenced heap. </p> </li>
</ul>
<p>A thread gets the handle to its heap by calling <xref href="GUID-C197C9A7-EA05-3F24-9854-542E984C612D.dita#GUID-C197C9A7-EA05-3F24-9854-542E984C612D/GUID-42AC433D-1C9C-3AC6-8640-EB1A7BA876B5"><apiname>User::Heap()</apiname></xref>. </p>
<p>See <xref href="GUID-D557CC2C-C045-5818-B2F7-9BD8BC39257D.dita">Address Space
and Process</xref> for more background on chunks and heaps.</p>
</conbody></concept>