|
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-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 |
|
13 thread's heap. A program's request for memory is allocated from this heap.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p>Each thread has a chunk which contains that thread's program stack. For |
|
15 the main thread of a process, this chunk also contains the thread's heap. |
|
16 A program's request for memory is allocated from this heap. For example, a |
|
17 code fragment such as: </p> |
|
18 <codeblock id="GUID-ED3A8BC9-7601-5035-B422-ED80E5504867" xml:space="preserve">CArrayFixFlat<...>* fixflat; |
|
19 ... |
|
20 fixflat = new (ELeave) CArrayFixFlat<...>(3);</codeblock> |
|
21 <p>causes a portion of memory to be allocated from the heap and its address |
|
22 returned to the caller. Memory from the heap must be explicitly requested |
|
23 and, importantly, explicitly freed by the program. </p> |
|
24 <p>If a process creates additional threads, then a new chunk is created for |
|
25 each new thread. Each chunk contains the thread's stack; if a new thread is |
|
26 not sharing an existing heap, then the chunk also contains a new heap. </p> |
|
27 <p>When a new thread is created, either: </p> |
|
28 <ul> |
|
29 <li id="GUID-C915A4D8-70D9-55B4-A16F-9729B1F8D94B"><p>a new heap is created |
|
30 for it </p> </li> |
|
31 <li id="GUID-E72B8DF5-CB52-5333-9D3E-EFDBAFE6CB59"><p>it uses the creating |
|
32 thread's heap </p> </li> |
|
33 <li id="GUID-20C6F186-6EF6-511E-9291-3273CA930B5D"><p>it uses an explicitly |
|
34 referenced heap. </p> </li> |
|
35 </ul> |
|
36 <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> |
|
37 <p>See <xref href="GUID-D557CC2C-C045-5818-B2F7-9BD8BC39257D.dita">Address Space |
|
38 and Process</xref> for more background on chunks and heaps.</p> |
|
39 </conbody></concept> |