1. 程式人生 > WINDOWS開發 >WIN32申請記憶體 物理頁 VirtualAlloc VirtualFree

WIN32申請記憶體 物理頁 VirtualAlloc VirtualFree

LPVOID VirtualAlloc(
LPVOID lpAddress,//指定記憶體地址,一般填NULL
DWORD dwSize,//分配記憶體大小 0x1000為1個物理頁
DWORD flAllocationType,//分配型別 MEM_COMMIT地址空間和物理頁都分  MEM_RESERVE只分地址空間                                          
DWORD flProtect //訪問保護型別
);                     

BOOL VirtualFree(
LPVOID lpAddress,//申請記憶體返回的指標
DWORD dwSize,//
釋放記憶體大小 DWORD dwFreeType //釋放型別 MEM_DECOMMIT釋放物理頁 MEM_RELEASE空間地址和物理頁都釋放 不過大小要填0 );

// VirtualAlloc.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <WINDOWS.H>
int main(int argc,char* argv[])
{
    LPVOID p = VirtualAlloc(NULL,0x1000,MEM_COMMIT,PAGE_READWRITE);

    VirtualFree(p,
0x1000,MEM_DECOMMIT); return 0; }