内存密集型应用程序的内存管理 [英] Memory management in memory intensive application

查看:691
本文介绍了内存密集型应用程序的内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在Windows上使用C ++开发内存密集型应用程序,您是否选择编写自己的自定义内存管理器从虚拟地址空间分配内存,或者允许CRT控制并为您进行内存管理?我特别关注由堆上的小对象的分配和释放引起的碎片。因为这个,我认为这个进程将耗尽内存,尽管有足够的内存,但是碎片了。

If you are developing a memory intensive application in C++ on Windows, do you opt to write your own custom memory manager to allocate memory from virtual address space or do you allow CRT to take control and do the memory management for you ? I am especially concerned about the fragmentation caused by the allocation and deallocation of small objects on heap. Because of this, I think the process will run out of memory eventhough there is enough memory but is fragmented.

推荐答案

最好的办法是不要实现一个,直到配置文件证明,CRT是碎片的内存,损害您的应用程序的性能。 CRT,核心操作系统和STL家伙花费了大量的时间来思考内存管理。

I think your best bet is to not implement one until profiles prove that the CRT is fragmenting memory in a way that damages the performance of your application. CRT, core OS, and STL guys spend a lot of time thinking about memory management.

很有可能你的代码在现有的分配器下表现不错,不需要更改。有一个更好的机会,比你有一个内存分配器第一次正确。我之前写过内存分配器的情况类似,这是一个艰巨的任务。不是那么令人惊讶,我继承的版本充满了碎片问题。

There's a good chance that your code will perform quite fine under existing allocators with no changes needed. There's certainly a better chance of that, than there is of you getting a memory allocator right the first time. I've written memory allocators before for similar circumstances and it's a monsterous task to take on. Not so suprisingly, the version I inherited was rife with fragmentation problems.

等待配置文件显示它是一个问题的另一个好处是,你也知道你是否已经修复任何东西。这是性能修复的最重要的部分。

The other advantage of waiting until a profile shows it's a problem is that you will also know if you've actually fixed anything. That's the most important part of a performance fix.

只要使用标准集合类和算法(例如STL / BOOST),稍后再插入新的分配器应该不是很难修复需要修复的代码库部分的周期。这是不太可能的,你将需要一个手编码分配器为您的整个程序。

As long as you're using standard collection classes an algorihtmns (such as STL/BOOST) it shouldn't be very hard to plug in a new allocator later on in the cycle to fix the portions of your code base that do need to be fixed. It's very unlikely that you will need a hand coded allocator for your entire program.

这篇关于内存密集型应用程序的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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