虚拟内存使用之前需要了解系统内存管理信息和虚拟地址空间的相关信息。
1.管理系统信息 —— 页面大小, 分配粒度 等基本的系统信息,CPU管理的信息。
使用函数: GetSystemInfo(LPSYSTEM_INFO psi)
2.管理内存的状态信息 —— 物理内存大小, 页交换文件的大小 等内存相关的信息
使用函数: lobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
3.管理地址空间的状态 ——查询是否给某个地址调拨物理存储器,是否可以读取某一个内存地址
使用函数: VirtualQuery(LPCVOID pvAddress, PMEMORY_BASIC_INFORMATION pmbi, DWORD dwLength);
Windows 操作内存的三种机制
虚拟内存 —— 用于管理大型对象数组或者大型结构数组
内存映射文件 —— 适合管理大型数据流,以及在同一台机器上运行多个进程之间的共享数据。
堆 —— 适合管理大量的小型对象
虚拟内存的操作方法
一,分配虚拟内存
PVOID VritualAlloc(PVOID pvAddress, SIZE_T dwSize, DWORD fdwAllocationType, DWORD fdwProtect)
参数说明
pvAddress : 需要预定的基地址,如果由系统自己决定可以为null, 如果给定值那么需要时分配粒度的整数陪。系统可以自动调整
dwSize: 需要预定的地址空间的大小。该值表示了具体需要预定几页。
fdwAllocationType : 该属性指定了如何分配内存,可以是预定地址空间区域,也可以是调拨物理存储交换页文件,另外还可以是设定可重置页。
fdwProtect: 给定区域的保护属性。
1) 预定地址空间区域 —— 分配虚拟地址空间,将需要的页表信息加载,但是不分配具体的页交换文件
其中fdwAllocationType = MEM_RESERVE
2) 给预定的地址空间区域调拨存储器 —— 这个函数才真正的从物理存储器的也交换文件调拨给指定的区域。可以预定一大块地址空间,但是只调拨其中的个别页,进行处理从而提高内存的利用率。
其中fdwAllocationType = MEM_COMMIT
3) 同时预定和调拨物理存储器 —— 先预定地址空间区域,然后马上给预定的区域调拨物理存储器
其中fdwAllocationType = MEM_COMMIT | MEM_RESERVE
4) 重置物理存储器的内容 —— 程序通过指定物理存储器没有被修改,从而减少系统页交换的操作时间。
其中fdwAllocationType = MEM_RESET
函数同预定地址空间的函数,关键是参数 fdwAllocationType 必须为MEM_COMMIT
二 释放虚拟内存
BOOL VirtualFree( LPVOID pvAddress, SIZE_T dwSize, DWORD fdwFreeType)
参数说明
pvAddress : 需要撤销的也交换文件的基地址
dwSize: 需要释放的物理存储器的大小
fdwAllocationType : 指定撤销的方式,主要是只撤销部分物理存储器也交换文件还是撤销整个地址空间区域。
1)撤销调拨物理存储器也交换文件 —— 仅仅释放调拨给地址空间区域的一部分存储器
pvAddress : 需要指定撤销物理存储器的基地址。
dwSize: 需要释放的物理存储器的大小
fdwAllocationType : MEM_DECOMMIT
2) 撤销整个物理存储交换文件和预定的地址空间区域
pvAddress : 由预定地址空间返回的基地址
wSize: 0 系统指导区域的大小
fdwAllocationType : MEM_RELEASE
分享到:
相关推荐
linux memory management study note
The Garbage Collection Handbook The Art of Automatic Memory Management, Jones, Hosking, Moss, 2012
Understand .NET memory management internal workings, pitfalls, and techniques in order to effectively avoid a wide range of performance and scalability problems in your software. Despite automatic ...
aarch64 Linux Kernel Memory Management, aarch64 Linux Kernel Memory Management, aarch64 Linux Kernel Memory Management
memory management 动态内存分配 FIFO算法
sdk2003 win32 Memory Management sdk2003 win32 Memory Management
Goals of memory management To provide a convenient abstraction for programming To allocate scarce memory resources among competing processes to maximize performance with minimal overhead
very detail description on the virtual memory management module in Linux kernel from concept to implementation.
PPT illustrates virtual memory.
Memory Management Simulator Used Java swing
Memory Management in the Java HotSpot Virtual Machine.pdf
MIT JOS Lab2: Memory Management,上海交通大学最新版本的JOS Lab2完整版代码,80分测试满分 详细解析地址:https://blog.csdn.net/qq_32473685/article/details/99625128
Pro Multithreading and Memory Management for iOS and OS X with ARC, Grand Central Dispatch epub
Garbage Collection Algorithms For Automatic Dynamic Memory Management
Objective-C Memory Management Essentials 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,...
C_C++ 内存管理算法和实现 Memory Management Algorithms and Implementation in C_C++ C_C++ 内存管理算法和实现 Memory Management Algorithms and Implementation in C_C++ C_C++ 内存管理算法和实现 ...
Objective-C Memory Management Essentials will familiarize you with the basic principles of Objective-C memory management, to create robust and effective iOS applications. You will begin with a basic ...
C/C++实现的内存管理算法教材,CHM格式
在codeproject里面下的,对于内存管理的理解很有帮助的