Symbian3/PDK/Source/GUID-539C4AA4-FF3F-4D6B-90A5-677092DBE54E.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     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-539C4AA4-FF3F-4D6B-90A5-677092DBE54E" xml:lang="en"><title>Exporting
       
    13 Global Data from a DLL</title><shortdesc>Exporting global data from a DLL to be accessed by either P.I.P.S.
       
    14 or Symbian C++ applications is one of the typical problems that developers
       
    15 encounter.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    16 <p>It is strongly recommended to avoid having global data in DLLs due to following
       
    17 reasons:</p>
       
    18 <ul>
       
    19 <li><p>EKA2 emulator allows only a DLL with WSD to load into a single process.</p></li>
       
    20 <li><p>RAM usage for WSD data chunk is atleast one 4K RAM page (the smallest
       
    21 possible RAM allocation), irrespective of how much static data is required.</p></li>
       
    22 <li><p>Chunks are a finite resource on ARMv5. Every process loading WSD enabled
       
    23 DLLs uses a chunk to hold the data.</p></li>
       
    24 <li><p>There are ARM architecture 4 and 5 specific costs and limitations that
       
    25 apply only to DLLs that link against “fixed processes”.</p></li>
       
    26 <li><p> There is a limit on the number of DLLs in a process with WSD. </p></li>
       
    27 </ul>
       
    28 <p>On having understood the above limitations, the following pattern can be
       
    29 used for exporting global data from a DLL:</p>
       
    30 <ol>
       
    31 <li id="GUID-CB5A6042-22D6-4A55-AB95-238D36B29E4D"><p>Do not export global
       
    32 variables. Within DLL, say there is one global variable, for example:</p><codeblock xml:space="preserve">int globalVal; </codeblock></li>
       
    33 <li id="GUID-441655B4-C2E0-4923-AA61-9AD71B9E8E43"><p>Export one method that
       
    34 returns a pointer to that variable.</p><codeblock xml:space="preserve">extern "C" EXPORT_C int* GlbData ()
       
    35     {
       
    36     return &amp;globalVal
       
    37     }
       
    38 </codeblock></li>
       
    39 <li id="GUID-8C06D549-3F94-455B-981D-D0D19B004BE1"><p>Define a macro for the
       
    40 user of the DLL. Within the DLL header (for example, <filepath>xxx.h</filepath>),
       
    41 define the following:</p><codeblock xml:space="preserve">#ifdef __cplusplus
       
    42 extern "C" 
       
    43 #endif
       
    44 IMPORT_C int* GlbData ();
       
    45 #define globalVal (*GlbData())</codeblock><p>And the usage is like: </p><codeblock xml:space="preserve">#include &lt;xxx.h&gt;  // DLL header
       
    46 int main()
       
    47     {
       
    48     int i = 0;
       
    49     globalVal = 10;
       
    50     globalVal++;
       
    51     i = globalVal;
       
    52     return 0;
       
    53     }
       
    54 </codeblock></li>
       
    55 </ol>
       
    56 </conbody></concept>