Home » Community » Coffee corner » Map implementation
Re: Map implementation [message #51570 is a reply to message #51569] |
Wed, 17 April 2019 18:39   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
Novo wrote on Wed, 17 April 2019 16:13mirek wrote on Wed, 17 April 2019 02:54
Well, nothing surprising there, right?
Yes, but ...
$ ./test_ht_perf
Mem used: 78128 Kb
Index<int> Add: 7.035
Index<int> Unlink: 12.272
Mem used: 2592740 Kb
Mem used after Sweep: 3800292 Kb
Mem used: 3769040 Kb
std::set<int> insert: 7.381
std::set<int> erase: 4.296
Mem used: 7603920 Kb
if (true) {
Vector<Index<int> > v;
v.SetCount(v_num);
const int isize = 100;
Cout() << "Mem used: " << MemoryUsedKb() - curMU << " Kb" << EOL;
TimeStop ts;
for (int i = 0; i < isize; ++i) {
const int jsize = v_num;
for (int j = 0; j < jsize; ++j)
v[j].Add(i);
}
Cout() << "Index<int> Add: " << ts.ToString() << EOL;
ts.Reset();
for (int i = 0; i < isize; ++i) {
const int jsize = v_num;
for (int j = 0; j < jsize; ++j)
v[j].UnlinkKey(i);
}
Cout() << "Index<int> Unlink: " << ts.ToString() << EOL;
Cout() << "Mem used: " << MemoryUsedKb() - curMU << " Kb" << EOL;
const int jsize = v_num;
for (int j = 0; j < jsize; ++j)
v[j].Sweep();
Cout() << "Mem used after Sweep: " << MemoryUsedKb() - curMU << " Kb" << EOL;
}
if (true) {
std::set<int>* v;
v = new std::set<int>[v_num];
const int isize = 100;
Cout() << "Mem used: " << MemoryUsedKb() - curMU << " Kb" << EOL;
TimeStop ts;
for (int i = 0; i < isize; ++i) {
const int jsize = v_num;
for (int j = 0; j < jsize; ++j)
v[j].insert(i);
}
Cout() << "std::set<int> insert: " << ts.ToString() << EOL;
ts.Reset();
for (int i = 0; i < isize; ++i) {
const int jsize = v_num;
for (int j = 0; j < jsize; ++j)
v[j].erase(i);
}
Cout() << "std::set<int> erase: " << ts.ToString() << EOL;
Cout() << "Mem used: " << MemoryUsedKb() - curMU << " Kb" << EOL;
}
Project is attached.
std::set<int> erase is three times faster than Index<int> Unlink.
After calling Index::Sweep even more memory is used. I guess this is a problem with the allocator.
And Index invalidates pointers.
So ...
Cool intresting catch.
Took me a while digging into the memory issue and it is really interesting - it looks like the problem is in this line
Quote:
void HashBase::FinishIndex()
{
int q = link.GetCount();
link.Reserve(hash.GetAlloc()); <==== HERE
link.AddN(hash.GetCount() - q);
for(int i = q; i < hash.GetCount(); i++)
LinkTo(i, link[i], hash[i] & UNSIGNED_HIBIT ? unlinked : Mapi(i));
}
If you comment it out, all works fine. The reason is that at that point, 'overreservation' of link in this particular leads to going from small blocks to large ones. Those small ones then are left free for further use, which in this example never materializes.
I will definitely keep this scenario for testing with the new Index... That said, this really is not likely to happen in real app.
Going to look into Unlink issue now.
|
|
|
 |
|
Map implementation
|
 |
|
Re: Map implementation
By: mirek on Fri, 22 March 2019 07:18
|
 |
|
Re: Map implementation
By: Novo on Wed, 27 March 2019 03:33
|
 |
|
Re: Map implementation
|
 |
|
Re: Map implementation
By: Novo on Tue, 02 April 2019 17:48
|
 |
|
Re: Map implementation
By: Novo on Tue, 02 April 2019 18:39
|
 |
|
Re: Map implementation
|
 |
|
Re: Map implementation
By: mirek on Mon, 08 April 2019 22:37
|
 |
|
Re: Map implementation
|
 |
|
Re: Map implementation
By: mirek on Tue, 09 April 2019 17:16
|
 |
|
Re: Map implementation
By: mirek on Wed, 10 April 2019 11:07
|
 |
|
Re: Map implementation
|
 |
|
Re: Map implementation
By: Novo on Wed, 10 April 2019 17:09
|
 |
|
Re: Map implementation
By: mirek on Wed, 10 April 2019 17:37
|
 |
|
Re: Map implementation
By: Novo on Sat, 13 April 2019 20:58
|
 |
|
Re: Map implementation
By: Novo on Sat, 13 April 2019 21:07
|
 |
|
Re: Map implementation
By: mirek on Sun, 14 April 2019 08:03
|
 |
|
Re: Map implementation
By: Novo on Sun, 14 April 2019 18:55
|
 |
|
Re: Map implementation
By: mirek on Sun, 14 April 2019 19:52
|
 |
|
Re: Map implementation
By: mirek on Tue, 16 April 2019 12:38
|
 |
|
Re: Map implementation
By: Novo on Tue, 16 April 2019 16:38
|
 |
|
Re: Map implementation
By: mirek on Tue, 16 April 2019 19:33
|
 |
|
Re: Map implementation
By: Novo on Tue, 16 April 2019 22:36
|
 |
|
Re: Map implementation
By: Novo on Wed, 17 April 2019 05:40
|
 |
|
Re: Map implementation
By: mirek on Wed, 17 April 2019 08:54
|
 |
|
Re: Map implementation
By: Novo on Wed, 17 April 2019 16:13
|
 |
|
Re: Map implementation
By: mirek on Wed, 17 April 2019 18:39
|
 |
|
Re: Map implementation
By: mirek on Fri, 07 June 2019 13:58
|
 |
|
Re: Map implementation
By: Novo on Tue, 25 June 2019 15:20
|
 |
|
Re: Map implementation
By: mirek on Wed, 26 June 2019 12:07
|
 |
|
Re: Map implementation
By: Novo on Mon, 01 July 2019 06:26
|
 |
|
Re: Map implementation
By: mirek on Mon, 01 July 2019 17:53
|
 |
|
Re: Map implementation
By: Novo on Sat, 13 April 2019 21:25
|
 |
|
Re: Map implementation
By: Novo on Wed, 10 April 2019 16:13
|
 |
|
Re: Map implementation
By: mirek on Wed, 10 April 2019 17:50
|
 |
|
Re: Map implementation
By: Novo on Wed, 10 April 2019 16:48
|
Goto Forum:
Current Time: Sat May 10 23:38:05 CEST 2025
Total time taken to generate the page: 0.00607 seconds
|