导致内存碎片的原因 Memory Fragmentation

  • 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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值