Vista堆发生了什么? [英] What's going on with the Vista heap?

查看:129
本文介绍了Vista堆发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更好地理解Windows Vista堆为何以这种方式运行.考虑以下非常简单的程序:

I'm trying to better understand why the Windows Vista heap behaves the way it does. Consider the following very simple program:

#include <vector>
#define NUM_ALLOCS 10000000

int _tmain(int argc, _TCHAR* argv[])
{
    for (int iteration=0; iteration<10000; ++iteration) {
        std::vector<unsigned char *> buffer;
        buffer.reserve(NUM_ALLOCS);
        for (int i=0;i<NUM_ALLOCS;++i) {
            buffer.push_back(new unsigned char);
        }
        for (int i=0;i<NUM_ALLOCS;++i) {
            delete buffer[i];
        }
    }

    return 0;
}

基本上,这是一个循环,每次迭代分配大量1个字节的块,然后释放它们.自然,该程序在分配缓冲区时会增加内存使用量,然后在释放缓冲区时减少内存使用量.

Basically this is a loop that for each iteration allocates a lot of 1 byte blocks and then releases them. Naturally, the memory usage of this program goes up while allocating the buffers and then down when the buffers are released.

我在Windows Vista 64位上看到的行为是峰值内存使用情况(由任务管理器或

The behavior that I am seeing on Windows Vista 64-bit is that the peak memory usage (as reported by task manager or by vmmap) stays roughly constant over time, whereas the lowest memory usage reported grows until it is close to the peak memory usage.

在Windows 7 64位上,报告的最低内存使用量不会随时间增长.

On Windows 7 64-bit the lowest memory usage reported does not grow over time.

我已经在两台具有8 GB/4 GB RAM的Windows Vista 64位计算机和一台具有4 GB RAM的Windows 7 64位计算机上进行了测试.我已经在低内存使用情况和高内存使用情况下测试了8 GB的计算机.

I've tested on two Windows Vista 64-bit machines with 8 GB / 4 GB RAM and one Windows 7 64-bit machine with 4 GB RAM. I've tested the 8 GB machine with both low and high memory usage scenarios.

我用Visual Studio 2005和2010构建了上面的示例,结果相同.

I've built the above example with Visual Studio 2005 and 2010 with the same result.

该示例没有做任何有用的事情,但是内存使用情况与我的程序类似(尽管非常紧凑),我试图弄清楚为什么它看起来比实际使用了更多的内存做.据我所知,内存是由堆管理器保存的.

This example isn't doing anything useful, but the memory usage scenario is similar (albeit heavily condensed) to a program of mine for which I've tried to figure out why it appears to use a lot more memory than it actually does. From what I can tell, the memory is being held by the heap manager.

是否有人对堆机制有任何见识? 我是否需要做一些额外的工作以说服堆管理器完全释放已使用的堆内存?我应该使用其他替代策略,例如创建一个单独的堆然后销毁它吗?

Does anyone have any insights on the heap mechanisms? Do I need to do something extra to convince the heap manager to fully release the used heap memory? Are there alternative strategies that I should use, such as creating a separate heap and then destroy it?

任何评论或见解都将受到赞赏!

Any comments or insights are appreciated!

推荐答案

可能是在我看来,我读到某个地方在Windows 7上默认启用了LFH.但是,快速搜索并没有显示确认信息,因此在这里我可能是错的.

It seems to me that I read somewhere that LFH is enabled by default on Windows 7. However, quick search didn't reveal the confirmation, so I may be wrong here.

不过,有一种简单的检查方法.调用 HeapQueryInformation

There is an easy way to check, though. Call HeapQueryInformation on a handle obtained from GetProcessHeap and compare the results on different systems.

这篇关于Vista堆发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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