Symbian3/PDK/Source/GUID-27C933F7-4634-57C8-B3D2-45C5563FECA4.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 11 Mar 2010 18:02:22 +0000
changeset 3 46218c8b8afa
parent 1 25a17d01db0c
child 5 f345bda72bc4
permissions -rw-r--r--
week 10 bug fix submission (SF PDK version): Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.

<?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-27C933F7-4634-57C8-B3D2-45C5563FECA4" xml:lang="en"><title>How
to use dynamic arrays</title><shortdesc>This document describes how to create templated arrays; that is,
an array of a particular type of object.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>All array classes are templated; the template value defines the type of
object which is to form an element of the array. This is true for arrays of
same length and variable length elements. The following example code constructs
an array of same length elements of type <codeph>TMyClass</codeph> using the
flat array buffer <codeph>CArrayFixFlat&lt;class T&gt;</codeph>. The array has
granularity 16:</p>
<codeblock id="GUID-E59CB1C7-4BFD-574B-97DD-28B82BEDB9BB" xml:space="preserve">CArrayFixFlat&lt;TMyClass&gt; array;
...
array = new (ELeave) CArrayFixFlat&lt;TInt&gt;(16);
...</codeblock>
<p>To construct an array of <codeph>TInt</codeph> values with a <i>granularity</i> of
16, implement code as follows:</p>
<codeblock id="GUID-6B599A36-21EE-50B0-BF18-00C84AEC50A7" xml:space="preserve">CArrayFixFlat&lt;TInt&gt;* array;
...
array = new (ELeave) CArrayFixFlat&lt;TInt&gt;(16);</codeblock>
<p>After construction, the array contains no elements and no memory is allocated
to the array buffer.</p>
<p><codeph>CArrayPtrFlat</codeph> is a specialised array where the elements
are <i>pointers</i> to <codeph>CBase</codeph> derived objects. To construct
an array whose elements are pointers to <codeph>CMyClass</codeph> objects:</p>
<codeblock id="GUID-5F63CDA5-2386-562F-A66D-6963A126314D" xml:space="preserve">CArrayPtrFlat&lt;CMyClass&gt;* array;
...
array = new (ELeave) CArrayPtrFlat&lt;CMyClass&gt;(16);</codeblock>
<p>To construct an array of same length elements of type <codeph>TMyClass</codeph> using <codeph>RArray&lt;class
T&gt;</codeph>:</p>
<codeblock id="GUID-13D94D48-B752-5A31-9CC6-BD94DC2DEE3A" xml:space="preserve">RArray&lt;TMyClass&gt; array; // this is on the stack
...
...                     // add entries etc
...
array.Close();          // called before the array goes out of scope</codeblock>
<p>To construct an array of pointers to <codeph>CMyClass</codeph> objects
using <codeph>RPointerArray&lt;class T&gt;</codeph>:</p>
<codeblock id="GUID-151C2968-19F5-5AA0-BB93-DCBFF023B0DA" xml:space="preserve">RPointerArray&lt;CMyClass&gt; array;  // this is on the stack
...
CMyClass* ptr = new (ELeave) CMyClass;
...
array.Append(ptr);
...
array.ResetAndDestroy();       // called before the array goes
                               // out of scope</codeblock>
</conbody></concept>