本文介绍了Re:在C ++中慢速手动'垃圾收集'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 谢谢大家的回复! 我的确使用向量< vector< nDimensionalPoint *作为Hashtable。 我的要求是查找对于给定坐标,n维点的值非常快 。 我将尝试STL Map或Multiset。也许这样可以更快地运行并且更节省内存。 我之前从未听说过游泳池分配器,但谷歌也会这样做。 但是当我不在我的向量向量中使用指针但只有 向量< vector< nDimensionalPoint时,对象的析构函数 nDimensionalPoint被调用,我想? br /> 祝你好运! Brey 荷兰 Thank you all for your replys ! Indeed I am using a vector<vector<nDimensionalPoint * as Hashtable.My requirement is to lookup the value of a point of n dimensions veryfast for given coordinates. I''m going to try an STL Map or Multiset. Maybe that works faster andmore memory efficient.I have never heard before of a pool allocator but will Google for it. But when I dont use pointers in my vector of vectors but onlyvector<vector<nDimensionalPoint, the destructor of the objectsnDimensionalPoint are called, I suppose ? Best regards !BreyThe Netherlands 推荐答案 是的,但是如果对象只包含双精度和整数,则析构函数 没有做任何事。不能比这快得多! Bo Persson Yes, but if the objects just contain doubles and ints, the destructordoesn''t have to do anything. Can''t be much faster than that!Bo Persson 是的,但如果对象只包含双打和整数,则析构函数 不需要做任何事情。不能比这快得多! Bo Persson Yes, but if the objects just contain doubles and ints, the destructordoesn''t have to do anything. Can''t be much faster than that!Bo Persson 好​​吧,这些对象包含2个值和一个数组: 它的实际值,它的虚数值和一个整数的坐标 数组(因为坐标的数量必须是可变的,可以是2 维直到12维)。 所以我需要一个真正的析构函数来删除[] int数组。 Well, the objects contain 2 values and one array:its real value, its imaginary value and the coordinates in an integerarray (because the number of coordinates have to be variable, can be 2dimensional up till 12 dimensional).So I need a real destructor which delete[] the int array. 我想我在之前的帖子中说过这个,但我会再说一遍:如果 你需要使用一个变长数组,只需使用一个向量,比如 这个: class nDimensionalPoint { public: double realValue; double imaginaryValue; std :: vector< intcoordinates; } ; 这样就没有必要定义一个析构函数,因为没有分配 的内存! 我希望这会有所帮助,Brey。 - Jean-Luc I think I said this in my previous post, but I''ll say it again: Ifyou ever need to use a variable-length array, just use a vector, likethis: class nDimensionalPoint{public:double realValue;double imaginaryValue;std::vector<intcoordinates;}; This way there''s no need do define a destructor, since there was nomemory allocated! I hope this helps, Brey. -- Jean-Luc 这篇关于Re:在C ++中慢速手动'垃圾收集'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 20:02