> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XMemMapPhysicalPages

> XMemMapPhysicalPages

# XMemMapPhysicalPages

[XMemAllocatePhysicalPages](/reference/system/xmem/functions/xmemallocatephysicalpages) によって割り当てられたページを仮想アドレス空間にマップします。

## Syntax

```cpp theme={null}
PVOID XMemMapPhysicalPages(  
         PVOID VirtualAddress,  
         ULONG_PTR NumberOfPages,  
         PULONG_PTR PageArray  
)  
```

### Parameters

*VirtualAddress*   \_In\_\
型: PVOID

ページをマップするアドレス。

*NumberOfPages*   \_In\_\
型: ULONG\_PTR

*PageArray* 内のエントリ数。

*PageArray*   \_In\_reads\_opt\_(NumberOfPages)\
型: PULONG\_PTR

マップするページを表すページ フレーム番号の配列。

### Return value

型: PVOID

物理ページがマップされた仮想アドレス。マッピングに失敗した場合は NULL。

マッピング失敗の場合、拡張エラー情報を取得するには <a href="https://msdn.microsoft.com/library/windows/desktop/ms679360(v=vs.85).aspx">GetLastError</a> を呼び出します。

## Remarks

仮想アドレス範囲は、[XMemVirtualAlloc](/reference/system/xmem/functions/xmemvirtualalloc) を **MEM\_RESERVE**、ページ サイズ **MEM\_64K\_PAGES** または **MEM\_2MB\_PAGES**、および **XMEM\_MAPPABLE** フラグとともに呼び出して、あらかじめ予約しておく必要があります。VirtualAlloc によって行われた **MEM\_PHYSICAL** アドレス予約は、このメモリのマッピングには使用できません。

仮想アドレス範囲にすでにマップされたページがある場合、それらはアンマップされます。さらに、メモリ領域をデコミットするために PageArray に NULL を指定することもできます。

**XMemMapPhysicalPages** を使用して、同じ物理ページを仮想アドレス空間で複数回マップできます。ページが複数回マップされる場合、複数のマッピングは同一のキャッシュ属性を指定する必要があります (キャッシュ属性が指定されない場合は CPU コヒーレントが暗黙的で、それ以外の場合は **PAGE\_NOCACHE** または **PAGE\_WRITECOMBINE** のいずれかです)。

<Note>MEM\_2MB\_PAGES で予約されたメモリに物理ページをマップする場合、物理ページは XMEM\_2MB\_CLUSTERS で割り当てられている必要があります。PageArray パラメーターには、各 2MB クラスターの最初の物理ページのみを含める必要があります。</Note>

例:

```cpp theme={null}
ULONG_PTR PageArray[64];
ULONG_PTR PageCount = RTL_NUMBER_OF(PageArray);
XMemAllocatePhysicalPages(XMEM_2MB_CLUSTERS, &PageCount, PageArray);

// Allocate 4MB of reserved space as both 64KB page sizes and 2MB page sizes
PVOID RWAddress = XMemVirtualAlloc(NULL,
    4 * 1024 * 1024,
    MEM_64K_PAGES | MEM_RESERVE,
    XMEM_CPU | XMEM_MAPPABLE,
    PAGE_READWRITE);

PVOID ROAddress = XMemVirtualAlloc(NULL,
    4 * 1024 * 1024,
    MEM_2MB_PAGES | MEM_RESERVE,
    XMEM_CPU | XMEM_MAPPABLE,
    PAGE_READONLY);

// Map the physical pages into the 64k address reservation
XMemMapPhysicalPages(RWAddress, PageCount, PageArray);

// Map the physical pages into the 2MB address reservation
// Use only the first physical page of each 2MB run
ULONG_PTR PageArray2MB[2];
PageArray2MB[0] = PageArray[0];
PageArray2MB[1] = PageArray[32];
XMemMapPhysicalPages(ROAddress, 2, PageArray2MB);

memset(RWAddress, 0x17, 4 * 1024 * 1024);
assert (memcmp(RWAddress, ROAddress, 4 * 1024 * 1024)==0);

// Unmap the regions, the address reservation is preserved
XMemMapPhysicalPages(ROAddress, 2, NULL);
XMemMapPhysicalPages(RWAddress, 64, NULL);

// Release the physical pages back to the MM
XMemFreePhysicalPages(PageCount, PageArray);

// Release the two reserved address regions
VirtualFree(RWAddress, 0, MEM_RELEASE);
VirtualFree(ROAddress, 0, MEM_RELEASE);
```

## Requirements

**ヘッダー:** xmem.h

**ライブラリ:** xmem.lib

**サポートされているプラットフォーム:** XBOX One ファミリー本体および XBOX Series 本体

## See also

[XMem リファレンス](/reference/system/xmem/xmem_members)\
[XMemVirtualAlloc](/reference/system/xmem/functions/xmemvirtualalloc)\
<a href="https://learn.microsoft.com/en-us/windows/desktop/api/memoryapi/nf-memoryapi-virtualfree">VirtualFree</a>\
[XMemFreePhysicalPages](/reference/system/xmem/functions/xmemfreephysicalpages)


## Related topics

- [Microsoft GDK ゲーム OS メモリ マネージャーの使用](/ja-jp/build/console-features/memory/system-memory-working.md)
- [XMemMapPhysicalPagesScatter](/ja-jp/reference/system/xmem/functions/xmemmapphysicalpagesscatter.md)
- [XMemFreePhysicalPages](/ja-jp/reference/system/xmem/functions/xmemfreephysicalpages.md)
- [Map](/ja-jp/reference/graphics/d3d12/interfaces/id3d12resource/methods/id3d12resource_map_public.md)
- [ApuMapApuAddress](/ja-jp/reference/audio/apu/functions/apumapapuaddress.md)
