windows虚拟内存管理的单位是64k对吧,在VC运行时库的源代码里面能看出来么?
VC的运行时库是有源代码的。例如malloc或者Heap调用的一些地方,能否看出来win的虚拟内存管理是按照什么样的方式划分单位的?
谢谢!
[解决办法]
运行库有源代码,但没ntdll.dll的源代码
[解决办法]
kernel32的HeapAlloc是转向导出ntdll的RtlAllocateHeap
[解决办法]
SYSTEM_INFO sysInfo = {0};
GetSystemInfo(&sysInfo);
//sysInfo.dwPageSize Specifies the page size and the granularity of page protection and commitment. This is the page size used by the VirtualAlloc function.
[解决办法]
ntdll!RtlAllocateHeap是用户模式的,VirtualAlloc是对NtAllocateVirtualMemory的简单封装
RtlAllocateHeap倒是在NtAllocateVirtualMemory上加了自己的一套算法
[解决办法]
HeapAlloc是先从NtAllocateVirtualMemory获取一大块内存,然后在其上建立自己的数据结构用于更快速的分配,如果预先NtAllocateVirtualMemory得到的够用,就不会调用NtAllocateVirtualMemory
ntdll!NtAllocateVirtualMemory是用户模式到ntoskrnl!NtAllocateVirtualMemory的入口
[解决办法]
HeapAlloc最小好像是8个字节
[解决办法]
继续跟踪_heap_alloc
HeapAlloc虽然比VirtualAlloc更轻量级,但也是一个通用的算法,并不非常适合一些特定的场合
如果你只是分配1k,2k,4k的大小,完全可以自己实现一个用slab分配法的内存池,先从VirualAlloc拿一大块(比如几兆),然后在上面建立自己的数据结构
slab算法专门针对只分配固定几种大小的场合,很快
[解决办法]
没源码就看反汇编
负载高是指你的程序还是整个操作系统
[解决办法]
这要看你分配的具体情况