Re: Help!!! Memory allocation!!!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



So, if I do the following things,
pSystem = MmAllocateContiguousMemory (...); //1. the memory must be Nonpaged?
pMdl = IoAllocateMdl(pSystem...);
MmBuildMdlForNonPagedPool(pMdl); or MmProbeAndLockPages(pMdl)???
pUser = MmMapLockedPages(pMdl, UserMode...);// Map to user space address

are they correct? (Some params are omitted.)



"Pavel Lebedinsky [MSFT]" wrote:

Q1. In MSDN, it says that MmAllocateContiguousMemory first attemps to
allocate a continuous range of memory from Nonpaged pool, if it fails,
then
allocates from unused pages. So, here, if it fails allcating from Nonpaged
pool and then successfully allocates the continuous range of memory, is
this
continuous range of memory still nonpaged or not?

It is.

Q2. MmBuildMdlForNonPagedPool, this routine receives an MDL that specifies
a
virtual memory buffer in nonpaged pool, and updates it to describe the
underlying physical pages. And the MDL virtual address that is input must
be
within the nonpaged portion of system space. So, here, if
MmAllocateContiguousMemory fails to allocate the continuous memory in
nonpaged pool but successfully allocates from unused pages, can I still
call
MmBuildMdlForNonPagedPool to build my MDL?

Yes.

Q3. If a memory is allcated from nonpaged pool, do I still call
MmProbeAndLockPages

Non-paged memory is already locked, there is no need to explicitly
lock it. MmProbeAndLockPages will actually assert on checked builds
if you give it an MDL with MDL_SOURCE_IS_NONPAGED_POOL
flag set.

If I want the access rights to be read, write and modify, how should I do?
Set the third parameter as IoReadAccess | IoWriteAccess | IoModifyAccess
or
otherwise?

Specify IoWriteAccess.



.



Relevant Pages

  • Re: Help!!! Memory allocation!!!
    ... allocate a continuous range of memory from Nonpaged pool, if it fails, ... allocates from unused pages. ... pool and then successfully allocates the continuous range of memory, ...
    (microsoft.public.development.device.drivers)
  • Re: Help!!! Memory allocation!!!
    ... Also, unless you are trying to map these physical pages into a UserMode virtual address, don't call MmMapLockedPages either for an MDL created with MmBuildMdlForNonPagedPool. ... allocate a continuous range of memory from Nonpaged pool, if it fails, then ... allocates from unused pages. ... pool and then successfully allocates the continuous range of memory, ...
    (microsoft.public.development.device.drivers)
  • Re: Framework 2.0 array redim unsatisfactory performance
    ... implementation details of Redim, Redim Preserve, and List. ... significantly higher object allocated overhead then List. ... ReDim simply allocates a new ... but I do not even attempt to test its memory ...
    (microsoft.public.dotnet.languages.vb)
  • Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
    ... This is an array of pointers to buffers that get set up ... the driver allocates the buffers (via an internal allocation ... routine from its own block of reserved memory). ... So I can map ...
    (microsoft.public.windowsce.platbuilder)
  • Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
    ... I've got a pretty complex driver I'm porting up at the moment ... This is an array of pointers to buffers that get set up ... the driver allocates the buffers (via an internal allocation ... routine from its own block of reserved memory). ...
    (microsoft.public.windowsce.platbuilder)