Win内存分配函数(GlobalAlloc/HeapAlloc/LocalAlloc/VirtualAlloc)
来源:互联网 发布:java synchronization 编辑:程序博客网 时间:2024/05/17 16:44
内存分配函数/内存管理API
参考:
Windows MSDN
http://msdn.microsoft.com/en-us/library/aa908768.aspx
附助资料:
http://blog.csdn.net/susubuhui/article/details/7315094
http://wenku.baidu.com/link?url=yxgCWePPV1kFaIUciEspYgm34wNAnMLDoduBlfsEEo-mW0JFRVEOkixomUjPatqw_jOXZcqQ1CLoeBSZqLuse1KiyHD6ysZTMIzLy_sPgPS
http://blog.csdn.net/sharecode/article/details/7464915
对于Windows来说,提供了一些API接口进行Heap内存管理,是独立于C++/C程序之外的,仅用于Windows平台的API。
大概分为下面几组接口:
老的Heap接口GlobalXXX(新程序不建议使用,这些函数存在主要是兼容以前写的程序):
GlobalAlloc/GlobalRelloc/GlobalFree:从Heap申请一块内存
GlobalLock/GlobalUnlock: 从GlobalAlloc的内存中申请一段内存
函数参数:
新的Heap接口HeapXXX:
HeapCreate/HeapDestroy/GetProcessHeap:从Heap中申请一块内存
HeapAlloc/HeapRelloc/HeapFree/HeapSize:从HeapCreate的内存中申请一段内存
HeapValidatee:查询Heap或Alloc的信息
当前进程Heap内存接口LocalXXX:
LocalAlloc/LocalReAlloc/LocalFree/LocalSize:从当前Heap的内存中申请一段内存,相当于从HeapAlloc从GetProcessHeap中申请内存。
虚拟地址内存接口: VirtualXXX
VirtualAlloc/VirtualFree/ VirtualProtect/VirtualQuery:从进程堆中申请页面内存数据。通常用于申请一段大内存,最少申请一页。reserves or commits a region of pages。
关于这一块详细请参考:http://blog.csdn.net/sharecode/article/details/7464915
malloc,new,VirtualAlloc,HeapAlloc这几组的执行效率:
参考:http://blog.csdn.net/susubuhui/article/details/7315094
分配大内存的时候 VirtualAlloc才能体现出优势,申请小内存时比较慢。
至于小块内存那就是HeapAlloc > malloc > new,因为都是调用HeapAlloc,直接使用HeapAlloc要快很多。
扩展的新接口xxxEx(不是所有版本都支持)
以Ex结尾,例如VitualAllocEx,可以指定process handle,从而从其它运行进程空间申请一段内存。
函数说明:
HeapCreate:
从内存区申请一段内存作为堆。This function reserves memory from the shared memory area.
HeapDestroy:
删除HeapCreate创建的堆。This function destroys the specified heap object.
GetProcessHeap:
获取当前进程的堆Handle。注意这个不能使用Destroy删除。This function obtains a handle to the heap of the calling process. This handle can then be used in calls to the HeapAlloc,HeapReAlloc,HeapFree, andHeapSize functions.
HeapAlloc:
从指定堆申请一段内存,该段内存是不被移动的。This function allocates a block of memory from a heap. The allocated memory is not movable.
HeapReAlloc:
从指定堆重新申请一段内存。This function reallocates a block of memory from a heap. The allocated memory is not movable.
HeapFree:
释入HeapAlloc或HeapReAlloc申请的内存。This function frees a memory block from a heap. The memory block was allocated by the HeapAlloc or theHeapReAlloc function.
HeapSize:
根据Handle、内存开始地址,查询一段HeapAlloc内存的大小。This function returns the size, in bytes, of a memory block allocated from a heap by the HeapAlloc orHeapReAlloc function.
HeapValidate:
检查Heap Handle或Heap Handle下申请的内存是否有效。
This function validates the specified heap. HeapValidate scans all the memory blocks in the heap and verifies that the heap control structures maintained by the heap manager are in a consistent state. The HeapValidate function can also be used to validate a single memory block within a specified heap without checking the validity of the entire heap.
LocalAlloc/LocalReAlloc/LocalFree/LocalSize:
从当前进程Heap中进行操作。该组函数相当于HeapXXX指定Heap Handle为当前进程Handle。函数参考HeapAlloc / HeapReAlloc/ HeapFree/ HeapSize作用。
LocalAlloc : This function allocates the specified number of bytes from the heap.
In the linear Windows Embedded CE API environment, there is no difference between the local heap and the global heap.LocalAlloc is equivalent to HeapAlloc(GetProcessHeap, …).
VirtualAlloc/VirtualFree/ VirtualProtect/VirtualQuery:
从当前进程空间中申请页面空间数据,最少申请一页。
The VirtualAlloc function reserves or commits a region of pages in the virtual address space of the calling process. Memory allocated by this function is automatically initialized to zero, unless MEM_RESET is specified.
To allocate memory in the address space of another process, use theVirtualAllocEx function.
- Win内存分配函数(GlobalAlloc/HeapAlloc/LocalAlloc/VirtualAlloc)
- Win内存分配函数(GlobalAlloc/HeapAlloc/LocalAlloc/VirtualAlloc)
- VC常用内存分配函数HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc,Malloc,New的异同
- VC常用内存分配函数HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc,Malloc,New的比较
- VC常用内存分配函数HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc,Malloc,New的异同
- HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc
- HeapAlloc、VirtualAlloc、GlobalAlloc和LocalAlloc
- HeapAlloc、VirtualAlloc、GlobalAlloc和LocalAlloc
- VirtualAlloc,GlobalAlloc,HeapAlloc三个分配内存函数的区别
- 内存分配相关,new , GlobalAlloc, VirtualAlloc, HeapAlloc
- 内存分配相关,new , GlobalAlloc, VirtualAlloc, HeapAlloc
- HeapAlloc、VirtualAlloc、GlobalAlloc和LocalAlloc、 alloc、new
- 内存管理函数HeapAlloc,LocalAlloc,VirtualAlloc,malloc,new的异同
- 内存管理函数HeapAlloc,LocalAlloc,VirtualAlloc,malloc,new的异同
- HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc,malloc,new的异同
- HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc,malloc,new的异同
- HeapAlloc,GlobalAlloc,LocalAlloc,VirtualAlloc,malloc,new的异同
- HeapAlloc, GlobalAlloc, LocalAlloc, VirtualAlloc, malloc, new的异同
- 在查询时不能多个节点进行查询再建立关系
- android-支持多种屏幕[利用资源提供最佳设备兼容性] 十四
- 在安装Scrapy爬虫工具时sudo aptitude install python-dev无法安装
- php-fpm的静态static和动态dynamic执行方式比较
- IDEA 集成的Subversion 使用中遇的问题
- Win内存分配函数(GlobalAlloc/HeapAlloc/LocalAlloc/VirtualAlloc)
- 科普游戏开发的三大步骤
- 乘机人记录分析api
- 缺陷报告的作用、要点、原则和二八定理
- swagger注释API详细说明
- 使用switch语句和if...else语句,计算2008年8月8日这一天,是该年中的第几天
- 2017对CSDN学院一些建议
- java 开源项目 免费
- 比较不错的几款开源的WPF Charts报表控件