zoukankan      html  css  js  c++  java
  • 【Windows核心编程】VirtualAlloc 例子

     1 // VirtualAlloc.cpp : 定义控制台应用程序的入口点。
     2 //
     3 #include "stdafx.h"
     4 #include <Windows.h>
     5 #include <process.h>
     6 #include <iostream>
     7 using namespace std;
     8 
     9 #ifdef UNICODE
    10 #define  PRINT wcout
    11 #else
    12 #define  PRINT cout
    13 #endif
    14 
    15 int _tmain(int argc, _TCHAR* argv[])
    16 {
    17     SIZE_T sizeOfLargePage = GetLargePageMinimum();
    18     if (0 == sizeOfLargePage)
    19     {
    20         cerr<<"error in GetLargePageMinium 
    "<<endl;
    21         return -1;
    22     }
    23     cout<<"sizeOfLargePage is "<<sizeOfLargePage<<endl;
    24 
    25     int nCount = 10;
    26 
    27     //PVOID pAddr = VirtualAlloc(NULL, sizeOfLargePage * nCount, MEM_LARGE_PAGES | MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
    28     PVOID pAddr = VirtualAlloc(NULL, sizeOfLargePage * nCount, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
    29 
    30     if (NULL == pAddr)
    31     {
    32         cerr<<"error in VirtualAlloc 
    ";
    33         return -2;
    34     }
    35 
    36     TCHAR szBuffer[] = _T("hello world!");
    37     size_t nBuffer = _countof(szBuffer); 
    38 
    39     
    40    // memcpy_s(pAddr, _countof(szBuffer), szBuffer, _countof(szBuffer)); //_countof参数只能是数组,返回字符数
    41     memcpy_s(pAddr, sizeof(szBuffer), szBuffer,sizeof(szBuffer));
    42 
    43 
    44     PRINT<<(TCHAR*)pAddr<<endl;
    45 
    46     VirtualFree(pAddr, 0, MEM_DECOMMIT | MEM_RELEASE); 
    47 
    48     return 0;
    49 }
  • 相关阅读:
    基于ModBus-TCP/IT 台达PLC 通讯协议解析
    TNS-12541: TNS: 无监听程序 解决方案
    一个很好的ping端口的工具
    上位机(开发)
    无名
    网站部署
    cordova 开发
    mono 开发
    调用 浏览器 插件
    MacBook 配置
  • 原文地址:https://www.cnblogs.com/cuish/p/3627392.html
Copyright © 2011-2022 走看看