C ++ Simulation在glibmm线程中填充内存,但不在循环中 [英] C++ Simulation fills memory in glibmm thread, but not in loop

查看:80
本文介绍了C ++ Simulation在glibmm线程中填充内存,但不在循环中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在研究一个程序,以进行多个模拟并确定与测量数据有关的最佳设置.
我将gtkmm工具包用于GUI,将glibmm用于多线程支持.

为此,我有一个名为SimulationCCD的对象.
我初始化该对象并使用run_simulation()运行它,如下所示:

Hi all,

I''m working on a program to do multiple Simulations and determine the optimal settings, related to measured data.
I use the gtkmm toolkit for a GUI and glibmm for multithread support.

For this purpose I have a an object named SimulationCCD.
I initialize this object and run it using run_simulation(), like this:

void run_sims()
{
    for (unsigned i=0;i<10000;i++)
    {
        SimulationCCD simccd(...some parameters here...);
        simccd.run_simulation();
    }
}



现在,如果我运行



Now if I run

run_sims()

,内存使用率将达到预期的低:每次运行后,SimulationCCD对象都会被破坏.
如果我在这样的线程中运行函数,则会发生完全不同的事情

memory usage is low as expected: The SimulationCCD object is destructed after every single run.
A completely different thing happens if I run the function in a thread like this

Glib::Thread* m_sim_thread=Glib::Thread::create(sigc::mem_fun(*this, &Regression::run_sims), true);


此代码导致增加的内存使用量.在这种情况下,SimulationCCD对象看起来没有被破坏.
程序的内存使用量只是未经检查而增加.

有没有人使用glibbm线程遇到此问题,并且有任何已知的解决方案吗? (最好使用glibmm或glib工具包)

最好的祝福,
Hugo van den Brand


This code results in increased memory usage. In this case it looks like the SimulationCCD objects are not destroyed.
The memory usage of the program just increases unchecked.

Has anyone experienced this problem using glibbm threads and are there any known solutions? (preferably using the glibmm or glib toolkit)

Best wishes,
Hugo van den Brand

推荐答案

我们没有希望根据提供的代码段为您提供帮助.我的建议是只创建1个仿真,并在每个析构函数中设置一个断点,以确保您认为正在发生的事情实际上正在发生.

如果可以确定剩余的内存分配量,则可以确定不删除哪个对象.如果您正在创建线程或使用位图,则可能是您没有正确释放资源.

完全可以是任何东西.
We have no hope of helping you based on the provided code snippet. My advice is to create just 1 simulation, and put a breakpoint in each destructor to make sure what you think is happening, is in fact happening.

If you can determine how much memory is remaining allocated, you can probably determine which object isn''t being deleted. If you''re creating threads or using bitmaps, it could be that you''re not properly freeing the resources.

It could quite literally be anything.


这篇关于C ++ Simulation在glibmm线程中填充内存,但不在循环中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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