Re:在C ++中慢速手动'垃圾收集'? [英] Re: Slow manual 'garbage collection' in C++ ??

查看:84
本文介绍了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 very
fast for given coordinates.

I''m going to try an STL Map or Multiset. Maybe that works faster and
more 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 only
vector<vector<nDimensionalPoint, the destructor of the objects
nDimensionalPoint are called, I suppose ?

Best regards !
Brey
The Netherlands

推荐答案

br ************* @ hotmail.com 写道:

谢谢大家的回复!


我确实使用了矢量< ; vector< nDimensionalPoint * as

Hashtable。我的要求是在给定坐标下非常快速地查找n

尺寸点的值。


我将尝试STL地图或多集。也许这样可以更快地运行并且更节省内存。

我之前从未听说过一个游泳池分配器,但谷歌会为它提供b
。 />

但是当我不在我的向量向量中使用指针而只有

向量< vector< nDimensionalPoint时,对象的析构函数

nDimensionalPoint被调用,我想?
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 very fast for given coordinates.

I''m going to try an STL Map or Multiset. Maybe that works faster and
more 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 only
vector<vector<nDimensionalPoint, the destructor of the objects
nDimensionalPoint are called, I suppose ?



是的,但是如果对象只包含双精度和整数,则析构函数

没有做任何事。不能比这快得多!

Bo Persson

Yes, but if the objects just contain doubles and ints, the destructor
doesn''t have to do anything. Can''t be much faster than that!
Bo Persson


17月17日,22:45,Bo Persson < b ... @ gmb.dkwrote:
On 17 jun, 22:45, "Bo Persson" <b...@gmb.dkwrote:

brey_maastri ... @ hotmail.com写道:
brey_maastri...@hotmail.com wrote:

谢谢大家的回复!
Thank you all for your replys !


我确实使用向量< vector< nDimensionalPoint *作为

Hashtable。我的要求是对给定坐标非常快速地查找n

维度的点的值。
Indeed I am using a vector<vector<nDimensionalPoint * as
Hashtable. My requirement is to lookup the value of a point of n
dimensions very fast for given coordinates.


我要尝试STL Map或Multiset。也许这样可以更快地运行并且更节省内存。

我之前从未听说过一个游泳池分配器,但谷歌会为它提供b

I''m going to try an STL Map or Multiset. Maybe that works faster and
more memory efficient.
I have never heard before of a pool allocator but will Google for
it.


但是当我在向量向量中不使用指针但只有

向量< vector< nDimensionalPoint时,析构函数为对象

nDimensionalPoint被调用,我想?
But when I dont use pointers in my vector of vectors but only
vector<vector<nDimensionalPoint, the destructor of the objects
nDimensionalPoint are called, I suppose ?



是的,但如果对象只包含双打和整数,则析构函数

不需要做任何事情。不能比这快得多!


Bo Persson


Yes, but if the objects just contain doubles and ints, the destructor
doesn''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 integer
array (because the number of coordinates have to be variable, can be 2
dimensional up till 12 dimensional).
So I need a real destructor which delete[] the int array.


6月17日,3:18 pm,brey_maastri ... @ hotmail.com写道:
On Jun 17, 3:18 pm, brey_maastri...@hotmail.com wrote:

>

好​​吧,这些对象包含2个值,一个数组:

它的实数值,它的虚数值和一个整数的坐标

数组(因为坐标的数量必须是可变的,可以是2
维直到12维)。

所以我需要一个真正的析构函数来删除[] int数组。
>
Well, the objects contain 2 values and one array:
its real value, its imaginary value and the coordinates in an integer
array (because the number of coordinates have to be variable, can be 2
dimensional 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: If
you ever need to use a variable-length array, just use a vector, like
this:

class nDimensionalPoint
{
public:
double realValue;
double imaginaryValue;
std::vector<intcoordinates;
};

This way there''s no need do define a destructor, since there was no
memory allocated!

I hope this helps, Brey.

-- Jean-Luc


这篇关于Re:在C ++中慢速手动'垃圾收集'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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