VTK使用越来越多的内存,变得很慢
vtk uses more and more memory and becomes slow.
我在应用程序中遇到了内存泄漏,并确定它是和vtk有关的东西。我在Windows 7和Visual Studio 2012上使用64bit的vtk 6.1.0。
我在使用更多的vtk算法时遇到了这种行为。当然不是操作系统占用内存,而是vtk。似乎在每次调用update vtk时,都会创建对象并将它们放入某种更新队列中,并且最终不会删除。考虑以下代码:
#include <vtkImageConstantPad.h>
#include <vtkImageData.h>
#include <ctime>
int main(int argc, char *argv[])
{
int c=0;
clock_t start;
size_t iterations = 1000;
while (c != '.'){
c = getchar();
start = clock();
for(size_t i=0; i<iterations; ++i){
vtkImageConstantPad* pad = vtkImageConstantPad::New();
vtkImageData* test = vtkImageData::New();
test->SetExtent(0,1,0,1,0,1);
test->AllocateScalars(VTK_FLOAT,1);
pad->SetInputData(test);
pad->SetOutputWholeExtent(0,2,0,2,0,2);
pad->Update(); //this is what makes it bad
pad->Delete();
test->Delete();
}
std::cout << "Time for " << iterations << ": " << static_cast<double>(clock() - start) / CLOCKS_PER_SEC << "sec" << std::endl;
}
return 0;
}
我的输出是:
Time for 1000: 0.816sec
Time for 1000: 1.879sec
Time for 1000: 3.454sec
etc.
所以每次调用update()
都会消耗更多的内存和时间,尽管for循环作用域中的所有对象都会被销毁。有谁能在其他平台上证实这一点,或者知道如何解决这个问题?
经过进一步调查,我发现并不是所有的机器都出现这个问题。最后,我发现我的Bitdefender杀毒软件在某种程度上扰乱了程序,导致了这种奇怪的行为。当我关闭它时,一切都像预期的那样工作。
相关文章:
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 为什么我可以使用比分配的内存更多的内存
- 多个"常量引用"变量可以共享同一个内存吗?
- 为什么我能够为阵列分配比计算机实际拥有的内存更多的内存
- 多线程程序中出现意外的内存泄漏
- 使用连续内存实现多态性
- 如何避免向类中添加越来越多的状态?
- 迭代器越来越多,并导致SEG故障
- C++应用程序如何使用比 RSS 内存更多的堆
- 在 CUDA 上__constant__内存和多 GPU
- 为什么bool占用的内存和int占用的内存一样多?C++
- 一次使用共享内存的多个实例
- 在越来越多的坐标范围内运行prim的最快方法
- C-Mex函数和共享内存的多个实例
- 内存的多线程编程
- VTK使用越来越多的内存,变得很慢
- 某个程序的堆栈内存有多大,是否有任何编译器标志可以设置它
- 我可以使用内存写入多个相邻的标准布局子对象
- c++输出越来越多的数字