当 QList 变得太大时应用程序崩溃
我制作了一个应用程序,必须在内存中存储大量数据以提高计算性能。
它是列表和对象的层次结构,其中顶部对象是 QList<myObject*>
。加载数据时,会创建许多 new myObject*
实例并将其添加到列表中。内存消耗增加,当达到 ~1.9Gb 时程序崩溃。我的计算机 (Vista) 有 4Gb RAM,我在其他 RAM 较小的计算机 (XP) 上进行了测试,并且在同一点崩溃。我不能使用超过 1.9Gb 的 RAM 吗?
当加载较小的文件并且根据“Windows 任务管理器”的内存使用量为(例如)1.2Gb 时,我可以处理数据。但如果我想加载另一个文件,即使在对所有对象调用 delete
并清除列表之后,增长也会从 1.2Gb 开始。为什么?
我尝试切换到QVector并调用squeeze(),但内存保持不变。我已经阅读了有关 QList 中动态内存分配的其他线程,但是在加载新文件之前真的没有办法重置内存吗?尤其是1.9Gb之后就崩溃了;按顺序加载 3 个小文件就可以了。
非常感谢您的任何建议。
I make an application which has to store a lot of data in memory to improve calculation performance.
It is a hierarchy of lists and objects where the top object is a QList<myObject*>
. When loading data, a lot of instances of new myObject*
are created and added to the list. The memory consumption grows and when it comes to ~1.9Gb the program crashes. My computer (Vista) has 4Gb RAM, and I have tested on other computers with less RAM (XP) and it crashes at the same point. Can I not use more than 1.9Gb RAM?
When a smaller file is loaded and memory usage according to "Windows task manager" is (say) 1.2Gb I can work with the data. But if I want to load another file, the growing starts from 1.2Gb even after calling delete
on all objects and clearing the list. Why?
I tried switching to QVector
and call squeeze()
, but memory stays the same. I have read the other threads here about dynamic memory allocation in QLists, but is it really no way to reset the memory before I load a new file? Especially since it crashes after 1.9Gb; loading 3 small files sequentially and I'm there.
Thanks a lot for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 32 位 Windows,则您的进程只能使用 2 GB 内存。您只是无法使用 32 位寻址更多内存。如果您需要更多内存,也许您应该更改为 64 位 Windows。
If you have 32-bit Windows, then your process can only use 2 GB of memory. You just cannot address more memory with 32 bits. If you need more memory, maybe you should change to 64-bit Windows.