【Windows核心编程】VirtualAlloc 例子

 // VirtualAlloc.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Windows.h>
#include <process.h>
#include <iostream>
using namespace std; #ifdef UNICODE
#define PRINT wcout
#else
#define PRINT cout
#endif int _tmain(int argc, _TCHAR* argv[])
{
SIZE_T sizeOfLargePage = GetLargePageMinimum();
if ( == sizeOfLargePage)
{
cerr<<"error in GetLargePageMinium \n"<<endl;
return -;
}
cout<<"sizeOfLargePage is "<<sizeOfLargePage<<endl; int nCount = ; //PVOID pAddr = VirtualAlloc(NULL, sizeOfLargePage * nCount, MEM_LARGE_PAGES | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
PVOID pAddr = VirtualAlloc(NULL, sizeOfLargePage * nCount, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (NULL == pAddr)
{
cerr<<"error in VirtualAlloc \n";
return -;
} TCHAR szBuffer[] = _T("hello world!");
size_t nBuffer = _countof(szBuffer); // memcpy_s(pAddr, _countof(szBuffer), szBuffer, _countof(szBuffer)); //_countof参数只能是数组,返回字符数
memcpy_s(pAddr, sizeof(szBuffer), szBuffer,sizeof(szBuffer)); PRINT<<(TCHAR*)pAddr<<endl; VirtualFree(pAddr, , MEM_DECOMMIT | MEM_RELEASE); return ;
}
上一篇:微信小程序 - 使用npm(第三方包)


下一篇:DirectSound播放PCM(可播放实时采集的音频数据)