Data Buffers

This document describes how device drivers allocate and access memory buffers.

Most device drivers need to use memory buffers for I/O operations. Drivers typically own memory buffers, allocate them, and access them through pointers. The thread should be in a critical section when it allocates or de-allocates memory.

// Tx and Rx Buffers
TUInt8* iTxBuffer;    
TUInt8* iRxBuffer;
// Logical Channel second stage constructor
TInt DExDriverLogicalChannel::DoCreate(TInt /*aUnit*/, const TDesC8* 
/*anInfo*/, const TVersion& aVer)
    {
    ...
    // Initialize the Tx Buffer
    iTxBuffer = (TUInt8*) Kern::Alloc(KTxBufferSize);
    if (!iTxBuffer)
        return KErrNoMemory;
    ...
    }

Memory buffers must be freed when they are not required. If this is not done, a memory leak occurs.

// Free Tx Buffer
Kern::Free(iTxBuffer)