Share via


AllocPhysMem

Other versions of this page are also available for the following:

Windows Mobile Not SupportedWindows Embedded CE Supported

8/28/2008

This function allocates physically contiguous memory.

Syntax

LPVOID AllocPhysMem(
  DWORD cbSize,
  DWORD fdwProtect,
  DWORD dwAlignmentMask,
  DWORD dwFlags,
  PULONG pPhysicalAddress
);

Parameters

  • cbSize
    [in] Number of bytes to allocate. The physical memory allocated is rounded up to the nearest page and is aligned on a 64-KB address.
  • fdwProtect
    [in] Specifies the protection desired. The following table shows possible values.

    Value Description

    PAGE_EXECUTE

    Enables execute access to the committed region of pages. An attempt to read or write to the committed region causes an access violation.

    PAGE_EXECUTE_READ

    Enables execute and read access to the committed region of pages. An attempt to write to the committed region causes an access violation.

    PAGE_EXECUTE_READWRITE

    Enables execute, read, and write access to the committed region of pages.

    PAGE_GUARD

    Pages in the region become guard pages. Any attempt to read from or write to a guard page causes the system to raise a STATUS_GUARD_PAGE exception and turn off the guard page status. Guard pages thus act as access alarms.

    The PAGE_GUARD flag is a page protection modifier. An application uses it with one of the other page protection flags, with one exception: It cannot be used with PAGE_NOACCESS. When an access attempt causes the system to turn off guard page status, the underlying page protection takes over.

    If a guard page exception occurs during a system service, the service typically returns a failure status indicator.

    PAGE_READONLY

    Enables read access to the committed region of pages. An attempt to write to the committed region causes an access violation. If the system differentiates between read-only access and execute access, an attempt to execute code in the committed region causes an access violation.

    PAGE_READWRITE

    Enables both read and write access to the committed region of pages.

  • dwAlignmentMask
    [in] Bit mask that describes the byte alignment needed. If it is set to zero, the default system alignment is used. If it is set to any other value, the kernel attempts to fulfill the memory request, based on the alignment request. The dwAlignmentMask parameter and a physical address determine whether the memory is aligned correctly for the request.
  • dwFlags
    Reserved for future use. Must be set to zero.
  • pPhysicalAddress
    [out] Pointer to a DWORD that stores the physical address of the memory allocation.

Return Value

A valid pointer indicates success. NULL indicates failure. Call GetLastError for extended error information.

Remarks

If there is no physically contiguous memory to fulfill the request, no attempt is made to move memory to fulfill the request.

Requirements

Header pkfuncs.h
Library coredll.lib
Windows Embedded CE Windows CE .NET 4.0 and later

See Also

Reference

Kernel Functions
FreePhysMem

Other Resources

Privileged APIs
Privileged APIs