Adaptation/GUID-0A6C8DB8-ED41-4243-BA96-CA691CF9CD19.dita
changeset 15 307f4279f433
equal deleted inserted replaced
14:578be2adaf3e 15:307f4279f433
       
     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-0A6C8DB8-ED41-4243-BA96-CA691CF9CD19" xml:lang="en"><title>Data
       
    13 Buffers</title><shortdesc>This document describes how device drivers allocate and access
       
    14 memory buffers.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    15 <section id="GUID-21C5B685-F546-45B5-A829-00B2DBCBF8E4">      
       
    16       <p>Most device drivers need to use memory buffers for I/O operations.
       
    17 Drivers typically own memory buffers, allocate them, and access them through
       
    18 pointers. The thread should be in a critical section when it allocates or
       
    19 de-allocates memory. </p> <codeblock id="GUID-B222000C-8344-5239-9546-4E831A3C0A6E" xml:space="preserve">// Tx and Rx Buffers
       
    20 TUInt8* iTxBuffer;    
       
    21 TUInt8* iRxBuffer;</codeblock> <codeblock id="GUID-A921D206-7243-5F0A-ADA3-0330D93A137F" xml:space="preserve">// Logical Channel second stage constructor
       
    22 TInt DExDriverLogicalChannel::DoCreate(TInt /*aUnit*/, const TDesC8* 
       
    23 /*anInfo*/, const TVersion&amp; aVer)
       
    24     {
       
    25     ...
       
    26     // Initialize the Tx Buffer
       
    27     iTxBuffer = (TUInt8*) Kern::Alloc(KTxBufferSize);
       
    28     if (!iTxBuffer)
       
    29         return KErrNoMemory;
       
    30     ...
       
    31     }</codeblock> <p>Memory buffers must be freed when they are not required.
       
    32 If this is not done, a memory leak occurs. </p> <codeblock id="GUID-688A360C-1B7A-5F3A-BB83-98EB8A4658F3" xml:space="preserve">// Free Tx Buffer
       
    33 Kern::Free(iTxBuffer)</codeblock>     </section>
       
    34 </conbody></concept>