Symbian3/PDK/Source/GUID-911CD800-2D1B-5D7B-A67C-66E01F91062C.dita
changeset 5 f345bda72bc4
parent 3 46218c8b8afa
child 14 578be2adaf3e
equal deleted inserted replaced
4:4816d766a08a 5:f345bda72bc4
     7     Nokia Corporation - initial contribution.
     7     Nokia Corporation - initial contribution.
     8 Contributors: 
     8 Contributors: 
     9 -->
     9 -->
    10 <!DOCTYPE concept
    10 <!DOCTYPE concept
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    12 <concept xml:lang="en" id="GUID-911CD800-2D1B-5D7B-A67C-66E01F91062C"><title>Heaps</title><shortdesc>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: </shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody><codeblock id="GUID-ED3A8BC9-7601-5035-B422-ED80E5504867" xml:space="preserve">CArrayFixFlat&lt;...&gt;* fixflat;
    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&lt;...&gt;* fixflat;
    13 ...
    19 ...
    14 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> </conbody></concept>
    20 fixflat = new (ELeave) CArrayFixFlat&lt;...&gt;(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>