Tech Support > Microsoft Windows > Drivers > NdisAllocateBuffer semantics
NdisAllocateBuffer semantics
Posted by Parag Warudkar on February 21st, 2005


I have a doubt surrounding usage of NdisAllocateBufferPool ,
NdisAllocateBuffer and NdisFreeBuffer. MSDN documentation did not answer my
question.

What are the general semantics of using memory allocated from
NdisAllocateBuffer?
Is the driver allowed to pass the same value in VirtualAddress parameter
multiple times across calls to NdisAllocateBuffer? If yes, what does the
NdisAllocateBuffer return every time - same memory, or does it free the
existing one and return new memory?
If, in the call to NdisAllocateBufferPool, the driver specifies 10 as a
value to NumberOfDescriptors what does it mean- Does it mean than Driver can
call NdisAllocateBuffer at the most 10 times before calling NdisFreeBuffer?
What happens if driver calls NdisAllocateBuffer 11th time without calling
NdisFreeBuffer?

Thanks

Parag
Can anybody provide a good example involving various scenarios?

Posted by Calvin Guan on February 21st, 2005


NdisAllocateBufferPool doesn't do too much in NTx and always returns NULL
IIRC. It's mainly for 9x/Me compatibility.
NDIS_BUFFERs are indeed MDLs.

There's noting in NDIS prevents you from doing so. It just builds an MDL for
the buffer for each invocation.

It's supposed to fail in the 11th call on 9x/Me.

HTH,
Calvin
--
Calvin Guan Software Engineer/Radeon NT Drivers
ATI Technologies Inc. Markham ON, Canada www.ati.com



Posted by Parag Warudkar on February 21st, 2005


"Calvin Guan" wrote:

Hmm.. No. It is used by recent 64bit wireless drivers on XP.

Sorry what's an MDL? Actually I wanted to ask does NdisAllocateBuffer return
the same block of memory if I pass in a previously allocated VirtualAddress?
Guess will have to find out by writing code. Now I could have done that
before asking but since past month I am waiting for the DDK to arrive !

Thanks!

Parag

Posted by Stephan Wolf [MVP] on February 22nd, 2005


On Mon, 21 Feb 2005 11:41:02 -0800, "Parag Warudkar"
<ParagWarudkar@discussions.microsoft.com> wrote:

NdisAllocateBuffer() does not allocate memory but rather associates
previously allocated memory with an NDIS_BUFFER.

The parameter that you pass to NdisAllocateBuffer() as
'VirtualAddress' can point to any valid memory address. That could be
a static array (global or local to a function). But usually its some
piece of memory that you previously allocated via
NdisAllocateMemoryWithTag() or NdisMAllocateSharedMemory().

An NDIS_BUFFER is just a descriptor structure for some memory area.
You then concatenate such buffers using NdisChainBufferAtBack() and/or
NdisChainBufferAtFront() to make up an NDIS_PACKET.

Note that a valid NDIS_PACKET consists of at least one NDIS_BUFFER.
And usually receive buffers are actually only one NDIS_BUFFER, but not
always.

+-------------+
| NDIS_PACKET |
+-------------+
|
v
+-------------+ +-------------+ +-------------+
| NDIS_BUFFER |-->| NDIS_BUFFER |-->| NDIS_BUFFER |-->
+-------------+ +-------------+ +-------------+
| | |
v v v
+-------------+ +-------------+ +-------------+
| memory area | | memory area | | memory area |
+-------------+ +-------------+ +-------------+

Stephan

Posted by Maxim S. Shatskih on February 24th, 2005


It is IoAllocateMdl + MmBuildMdlForNonPagedPool.

It does not allocate memory. It allocates the descriptor only, the memory
itself must be allocated somewhere else.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com




Similar Posts