Share via


NdisAllocateNetBuffer (Compact 2013)

3/26/2014

Call this function to allocate and initialize a NET_BUFFER structure from a NET_BUFFER structure pool.

Syntax

PNET_BUFFER
  NdisAllocateNetBuffer(
    IN NDIS_HANDLE  PoolHandle,
    IN PMDL  MdlChain,
    IN ULONG  DataOffset,
    IN SIZE_T  DataLength
    );

Parameters

  • MdlChain
    A pointer to an MDL chain that NDIS uses to initialize the new NET_BUFFER structure. MdlChain can be NULL.
  • DataOffset
    The initial offset, in bytes, from the start of the buffer to the start of the used dataspace in the MDL chain. Dataspace ahead of this offset is unused dataspace. Therefore, this value also represents the initial amount of available backfill space in the MDL chain. If MdlChain is NULL, DataOffset must be 0.
  • DataLength
    The length of the used dataspace, in bytes, in the MDL chain. If MdlChain is NULL, DataLength must be 0.

Return Value

NdisAllocateNetBuffer returns a pointer to the NET_BUFFER structure that NDIS allocated. If the allocation was unsuccessful, this pointer is NULL.

Remarks

Call NdisFreeNetBuffer to free a NET_BUFFER structure that was allocated from a NET_BUFFER structure pool.

The preallocated NET_BUFFER can be reused by reinitializing it with another MDL chain when it owns NET_BUFFER, but the DataOffset, DataLength, CurrentMdl, and CurrentMdlOffset fields in NET_BUFFER must be consistent with the new MDL chain.

For example, if the original MDL chain contains X DataLength and Y DataOffset, and CurrentMdl starts with the second MDL (say M) in the original MDL chain, CurrentMdlOffset is Z. The MdlChain field in NET_BUFFER_DATA then has to point to a new MDL chain that contains X' DataLength and Y' DataOffset. If CurrentMdl starts with the third MDL (say M') in the new MDL chain, CurrentMdlOffset is Z' and the following macros must be used to set fields in NET_BUFFER:

NET_BUFFER_FIRST_MDL(_NB) = New MDL chain;
NET_BUFFER_DATA_LENGTH(_NB) = X';
NET_BUFFER_DATA_OFFSET(_NB) = Y';
NET_BUFFER_CURRENT_MDL(_NB) = M';
NET_BUFFER_CURRENT_MDL_OFFSET(_NB) = Z';

Requirements

Header

ndis.h

See Also

Reference

NDIS NET_BUFFER Functions
NET_BUFFER
NdisAllocateNetBufferPool
NdisFreeNetBuffer