- load过多的DLL,DLL的内存空间与堆空间会相互影响
- 使用HeapAlloc申请内存,导致存在大量小块内存,且这些小块内存leaked,导致没有一个大块连续的内存空间可供分配;或者不同生命周期,不同大小的内存同时申请,申请时是同时的,但是释放却不同时,会导致内存空间不连续
- 在Vista[The information in this topic applies to Windows Server 2003 and Windows XP. Starting with Windows Vista, the system uses the low-fragmentation heap (LFH) as needed to service memory allocation requests. Applications do not need to enable the LFH for their heaps.]
- LFH只有在size大于16KB时才使用,且会申请所得一个满足申请大小的且满足8Bytes倍数的最小的一块内存。
- VirtualAlloc申请内存的单位是4KB,而HeapAlloc可以申请小于4KB的内存,HeapAlloc底层调用VirtualAlloc,在其之上又做了一个管理的封装
- The LFH is not a separate heap. Instead, it is a policy that applications can enable for their heaps. When the LFH is enabled, the system allocates memory in certain predetermined sizes. When an application requests a memory allocation from a heap that has the LFH enabled, the system allocates the smallest block of memory that is large enough to contain the requested size.
- The system does not use the LFH for allocations larger than 16 KB, whether or not the LFH is enabled.
- To enable the LFH for a heap, use the GetProcessHeap function to obtain a handle to the default heap of the calling process, or use the handle to a private heap created by the HeapCreate function. Then call the HeapSetInformation function with the handle.
导致内存碎片的原因 Memory Fragmentation
最新推荐文章于 2023-11-09 13:14:35 发布