hash_map question

  • Thread starter Thread starter filox
  • Start date Start date
F

filox

i just don't get it:

hash_map<double, int> mapa;

double md = 0;

for(int j=0;j<1000000;++j)

{

mapa[md] = 3;

md++;

}



the above code takes up 70 MB of RAM. how??? any ideas?
 
filox said:
i just don't get it:

hash_map<double, int> mapa;

double md = 0;

for(int j=0;j<1000000;++j)

{

mapa[md] = 3;

md++;

}



the above code takes up 70 MB of RAM. how??? any ideas?

You're storing one million items in a hash_map, which has significant
overhead (hash buckets and linked lists, etc), why are you surprised?

Because of the uncertain equality of floating-point numbers, using doubles
as hash_map keys has questionable utility.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top