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 }
  • 相关阅读:
    雪花算法 适用于ID 自增
    SB ,mybatis generator 插件 实现 更新操作
    spark优化
    Hive的导入导出方式汇总
    推荐系统架构图
    DBScan算法
    机器学习-逻辑回归算法
    机器学习-微博精准营销
    机器学习-TF-IDF算法
    机器学习-KNN识别手写数字
  • 原文地址:https://www.cnblogs.com/cuish/p/3627392.html
Copyright © 2011-2022 走看看