C ++程序以std :: bad_alloc终止,但是valgrind报告没有内存泄漏 [英] C++ program dies with std::bad_alloc, BUT valgrind reports no memory leaks

查看:71
本文介绍了C ++程序以std :: bad_alloc终止,但是valgrind报告没有内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序失败,并显示"std :: bad_alloc"错误消息.该程序具有可伸缩性,因此我已经在使用valgrind的较小版本上进行了测试,并且没有内存泄漏.

My program fails with 'std::bad_alloc' error message. The program is scalable, so I've tested on a smaller version with valgrind and there are no memory leaks.

这是统计力学的一种应用,因此我基本上是在制造数百个对象,更改其内部数据(在这种情况下,是stl的double的向量),然后写入数据文件.对象的创建位于循环内,因此在结束时,内存是可用的.像这样:

This is an application of statistical mechanics, so I am basically making hundreds of objects, changing their internal data (in this case stl vectors of doubles), and writing to a datafile. The creation of objects lies inside a loop, so when it ends the memory is free. Something like:

for (cont=0;cont<MAX;cont++){
         classSection seccion;
         seccion.GenerateObjects(...);
         while(somecondition){
                seccion.evolve();
                seccion.writedatatofile();
         }}

因此,有两个变量设置程序的计算时间,系统大小和运行次数.只有运行多次的大型系统才会崩溃.关于如何解决此内存问题的任何想法?

So there are two variables which set the computing time of the program, the size of the system and the number of runs. There is only crash for big systems with many runs. Any ideas on how to catch this memory problem?

谢谢

推荐答案

在调试器下运行程序,以使该程序在引发异常后停止,您可以观察调用堆栈.

Run the program under debugger so that it stops once that exception is thrown and you can observe the call stack.

三个最可能的问题是:

这篇关于C ++程序以std :: bad_alloc终止,但是valgrind报告没有内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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