Virtual Memory Function Demo
来源:互联网 发布:回文c语言 编辑:程序博客网 时间:2024/06/05 18:56
#include <Windows.h>#include <iostream>using namespace std;int main(){ // Reserve virtual address space LPVOID lpvBase = VirtualAlloc(NULL, 64*1024, MEM_RESERVE, PAGE_READWRITE); if (lpvBase == NULL) { cout << "VirtualAlloc failed with error: " << GetLastError() << endl; return -1; } // Allocate physical storage for the reserved memory pages LPVOID lpBuffer = VirtualAlloc(lpvBase, 4*1024, MEM_COMMIT, PAGE_READWRITE); if (lpBuffer == NULL) { cout << "VirtualAlloc failed with error: " << GetLastError() << endl; return -1; } // Operate on the allocated memory sprintf((char*)lpBuffer, "Hello Kitty: %s", "WangYao"); cout << (char*)lpBuffer << endl; // Decommit allocated memory BOOL flag = VirtualFree(lpBuffer, 4*1024, MEM_DECOMMIT); if (flag) { cout << "VirtualFree with MEM_DECOMMIT successfully." << endl; } else { cout << "VirtualFree with MEM_DECOMMIT failed with error: " << GetLastError() << endl; return -3; } // Release allocated memory flag = VirtualFree(lpvBase, 0, MEM_RELEASE); if (flag) { cout << "VirtualFree with MEM_RELEASE successfully." << endl; } else { cout << "VirtualFree with MEM_RELEASE failed with error: " << GetLastError() << endl; return -4; } system("pause"); return 0;}
0 0
- Virtual Memory Function Demo
- virtual memory
- Virtual Memory
- Virtual Memory
- virtual function
- Virtual function
- virtual function
- virtual function
- Virtual Function
- Virtual memory management
- 虚拟内存(Virtual Memory)
- What is Virtual Memory?
- Virtual Memory technical specification
- Playing with Virtual Memory
- 关于Virtual Memory
- Virtual process memory
- Playing with Virtual Memory
- How Virtual Memory Works
- 黑马程序员—static关键字—知识点总结
- Heap,创建进程私有堆
- Codeforces534A:Exam
- (1.4.8.3)腾讯2013校园招聘
- Android---20---CheckBox复选框
- Virtual Memory Function Demo
- Android的API Demos
- 从零开始启动一个项目,需要哪些准备工作
- 华为在线测试题[基础篇]--求最小公倍数
- MapFileView示例
- 用Hexo写博客 - ERROR Local hexo not found in xxx
- 用wordpress搭建博客
- Codeforces534B:Covered Path
- 剑指offer--孩子们的游戏(圆圈中最后剩下的数)