我如何解决在C ++服务器程序中的堆碎片? [英] How do I workaround heap fragmentation in a C++ server program?

查看:332
本文介绍了我如何解决在C ++服务器程序中的堆碎片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

堆碎片可能导致预计连续运行多个月的服务器应用程序突然开始出现故障,认为它内存不足。

Heap fragmentation can cause a server application that is expected to run continuously for many months to suddenly start malfunctioning thinking that it's out of memory.

让我们假设,我尽我所能在我的VC ++服务器应用程序中尽量减少运行时堆碎片,但仍然建立并导致问题。例如,我可以每月或每半百万请求处理自动重新启动应用程序 - 安全地停止它,并安全地重新启动一个新的堆。

Let's assume that I've done my best to minimize runtime heap fragmentation in my VC++ server application but still it builds up and causes problems. I could for example automatically restart the application every month or every half million requests processed - safely stop it and safely start again with a new heap. What else can I do to workaround heap fragmentation?

推荐答案

一个好的起点是启用低碎片堆和检查天气仍然碎片。

A good starting point is to enable the low fragmentation heap and check weather it still fragments.

  HANDLE heaps[1025];
  DWORD nheaps = GetProcessHeaps((sizeof(heaps) / sizeof(HANDLE)) - 1, heaps);
  for (DWORD i = 0; i < nheaps; ++i) {
    ULONG  enableLFH = 2;
    HeapSetInformation(heaps[i], HeapCompatibilityInformation, &enableLFH, sizeof(enableLFH));
  }

这个新引入的内存管理器默认情况下在Vista / Server 2008上打开。 ..
所以如果你确定世界在新的服务器操作系统上更好,这可能是原因。

This newly introduced memory manager is switched on by default on Vista/Server 2008 ... So if you determine that world is better on newer Server OS this might be the reason.

低分段堆被引入了一个service pack

The low fragmentation heap was introduced with a service pack of Windows 2000 but it has to be aktively enabled till Windows Vista.

有一个工具 vmmap ,它提供了内存容易的概述,并且如果碎片发生了很好的概述。

There is a tool vmmap which gives an overview on memory easy and gives a good overview if fragmentation happens.

这篇关于我如何解决在C ++服务器程序中的堆碎片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆