Re: Slow manual 'garbage collection' in C++ ??
brey_maastricht@hotmail.com wrote:
In a scientific computation I need to store a lot of Point objects
(which have an array of doubles and 2 ints as fields).
To quickly search among all these points I have designed a Hashtable
to store them; a bucket/vector of buckets/vectors.
The hashtable is filled with Points objects in a while loop.
...
My C++ programm is very fast without emptying the hashtable. But then
I have a huge memory leak; and my swapfile grows enormouly.
With emptying the hashtable my C++ programm becomes dramatically
slow.....even slower than my Java programm.
So the question is: What to do now ?? It cannot be the case that
preventing a memory leak, slows down the computations ??
You could redesign the stuff for speed by using
e.g. continous vectors - and hash separate
integer indexes which point into these:
// [PSEUDO]
vector<int>indexarray; // <= 0 .. NUMPOINTS-1
struct coordinates {
vector<double>x; // <= 0 .. NUMPOINTS-1
vector<double>y; //
vector<double>z; //
vector<int>data1;
vector<int>data2;
};
or use the more traditional approach
with the same index array:
vector<int>indexarray; // <= 0 .. NUMPOINTS-1
struct coordinates { double x,y,z; int data1,data2; };
vector<coordinates>v; // <= 0 .. NUMPOINTS-1
Why did you design a hash algorithm instead
using a std::map<whatever, whatelse> (whats wrong with it?).
What exactly is hashed, what has to be looked up fast?
Regards
Mirco