hash table memory question

F

filox

so, i'm using the hash_map that comes with MS visual studio, and it seems to
spend an awful lot of memory. what i basiclly have is something like this:
hash_map<char*, int> a;
char* b = new char[17];
int i;
//some code that initializes b and i
a = i;

i do that for a huge amount of data and end up with 470 MB of memory for the
table. now, if i got it right, it should actually use (17*1+4)*3700000 = 78
MB ((17*sizeof(char) + sizeof(int)) * number_of_times_i_do_the_hashing). so,
any ides what is going on?
does hash_map use some extra memory to keep track of things and if so, is
there some other implementation of a hash table that i could use?
or am i just not seeing something?
 
V

Victor Bazarov

filox said:
so, i'm using the hash_map that comes with MS visual studio, and it

Since your question is compiler-specific, you should consider asking
in the newsgroup for that compiler: microsoft.public.vc.language.
seems to spend an awful lot of memory. what i basiclly have is
something like this: hash_map<char*, int> a;
char* b = new char[17];
int i;
//some code that initializes b and i
a = i;

i do that for a huge amount of data and end up with 470 MB of memory
for the table. now, if i got it right, it should actually use
(17*1+4)*3700000 = 78 MB ((17*sizeof(char) + sizeof(int)) *
number_of_times_i_do_the_hashing).


How do you arrive at that formula?
so, any ides what is going on?

I bet folks in m.p.v.l know.
does hash_map use some extra memory to keep track of things and if
so, is there some other implementation of a hash table that i could
use?
Probably.

or am i just not seeing something?

Are you looking? If the hash_map you're using is a template (and it
looks like one), you should be able to see all of it in the header
file that you're including in your source. "Use the Source, Luke!"

V
 
T

Thomas Tutone

filox said:
so, i'm using the hash_map that comes with MS visual studio,

It's non-standard - i.e., it's not part of the C++ Standard.
and it seems to
spend an awful lot of memory. what i basiclly have is something like this:
[snip]

is
there some other implementation of a hash table that i could use?

Try tr1::unordered_map.

Best regards,

Tom
 
F

filox

Thomas Tutone said:
It's non-standard - i.e., it's not part of the C++ Standard.

yeah, another question - why isn't there a hash table implementation that is
a part of Standard (as a part of STL, for example)? i mean, it's not like
hash tables are rarely used or something...
 
T

Thomas Tutone

filox said:
yeah, another question - why isn't there a hash table implementation that is
a part of Standard (as a part of STL, for example)? i mean, it's not like
hash tables are rarely used or something...

There is, sort of. It's called tr1::unordered_map. It's part of the
C++ Library Extensions Technical Report 1, released by the C++
Standards Committee. I mentioned tr1::unordered_map in my prior reply
as well.

Best regards,

Tom
 

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

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,539
Members
48,286
Latest member
Amaya678

Latest Threads

Top