473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

hash table...again

first of, i'd like to excuse myself for writing in this group, even though i
know this is not a standard C++ question. i've written to
microsoft.public.dotnet.lang.vc but no one seems to be answering me, and
it's pretty urgent.
any way, i have something like this:

hash_map<double, intmapa;

double md = 0;

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

{

mapa[md] = 3;

md++;

}

as you can see, i'm simply trying to hash a lot of data. my problem is that
this uses up 70 MB of memory,which seems to me a bit too much. any ideas
what went wrong?
again, sorry for being offtopic

--
You're never too young to have a Vietnam flashback
Nov 1 '06 #1
11 1876
filox wrote:
first of, i'd like to excuse myself for writing in this group, even though i
know this is not a standard C++ question. i've written to
microsoft.public.dotnet.lang.vc but no one seems to be answering me, and
it's pretty urgent.
Actually, it's not off-topic. FAQ 5.9 says that the topic here is the
standard C++ language and libraries and "planned extensions and
adjustments." TR1, some planned extensions to the standard library,
includes unordered_map, which is (I believe) essentially the same as
hash_map but with a different name so as not to cause problems with
code using the common extension you are using.
any way, i have something like this:

hash_map<double, intmapa;

double md = 0;

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

{

mapa[md] = 3;

md++;

}

as you can see, i'm simply trying to hash a lot of data. my problem is that
this uses up 70 MB of memory,which seems to me a bit too much. any ideas
what went wrong?
How do you know it takes 70 MB?

Cheers! --M

Nov 1 '06 #2
"mlimber" <ml*****@gmail.comwrote in message
news:11********************@e64g2000cwd.googlegrou ps.com...
filox wrote:
>first of, i'd like to excuse myself for writing in this group, even
though i
know this is not a standard C++ question. i've written to
microsoft.public.dotnet.lang.vc but no one seems to be answering me, and
it's pretty urgent.

Actually, it's not off-topic. FAQ 5.9 says that the topic here is the
standard C++ language and libraries and "planned extensions and
adjustments." TR1, some planned extensions to the standard library,
includes unordered_map, which is (I believe) essentially the same as
hash_map but with a different name so as not to cause problems with
code using the common extension you are using.
>any way, i have something like this:

hash_map<double, intmapa;

double md = 0;

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

{

mapa[md] = 3;

md++;

}

as you can see, i'm simply trying to hash a lot of data. my problem is
that
this uses up 70 MB of memory,which seems to me a bit too much. any ideas
what went wrong?

How do you know it takes 70 MB?
because the windows task manager says so...
Nov 1 '06 #3
filox wrote:
"mlimber" <ml*****@gmail.comwrote
How do you know it takes 70 MB?

because the windows task manager says so...
>From what I've read, the Task Manager is not a trustworthy source of
information on this count. Ask about reliable ways to calculate memory
usage in a Windows newsgroup, and once you are confident in the
numbers, ask here again if necessary.

Cheers! --M

Nov 1 '06 #4
filox wrote:
first of, i'd like to excuse myself for writing in this group, even though i
know this is not a standard C++ question. i've written to
microsoft.public.dotnet.lang.vc but no one seems to be answering me, and
it's pretty urgent.
any way, i have something like this:

hash_map<double, intmapa;

double md = 0;

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

{

mapa[md] = 3;

md++;

}

as you can see, i'm simply trying to hash a lot of data. my problem is that
this uses up 70 MB of memory,which seems to me a bit too much. any ideas
what went wrong?
You could try to use the constructor to tell the container its size
beforehand, hence preventing multiple reallocation and exponential
memory reservation to amortize it.
Nov 1 '06 #5
"loufoque" <lo******@remove.gmail.comwrote in message
news:45***********************@news.free.fr...
filox wrote:
>first of, i'd like to excuse myself for writing in this group, even
though i know this is not a standard C++ question. i've written to
microsoft.public.dotnet.lang.vc but no one seems to be answering me, and
it's pretty urgent.
any way, i have something like this:

hash_map<double, intmapa;

double md = 0;

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

{

mapa[md] = 3;

md++;

}

as you can see, i'm simply trying to hash a lot of data. my problem is
that this uses up 70 MB of memory,which seems to me a bit too much. any
ideas what went wrong?

You could try to use the constructor to tell the container its size
beforehand, hence preventing multiple reallocation and exponential memory
reservation to amortize it.
that sounds like it could help. only, i don't know how to do it...
could you write an example how to call a constructor with a size of ,say,
100 bytes?

thanks
Nov 1 '06 #6
filox wrote:
that sounds like it could help. only, i don't know how to do it...
could you write an example how to call a constructor with a size of ,say,
100 bytes?
1) I already told you it is in constructor
2) If you have doubts you should check your reference documentation
3) It is the same syntax than with all other containers.

Nov 1 '06 #7
loufoque wrote:
filox wrote:
>that sounds like it could help. only, i don't know how to do it...
could you write an example how to call a constructor with a size of
,say, 100 bytes?

1) I already told you it is in constructor
2) If you have doubts you should check your reference documentation
3) It is the same syntax than with all other containers.
That's too broad. The standard sequence containers (vector, list, deque)
have constructors that initialize them with a specified number of
elements. The standard associative containers (set, multi_set, map,
multi_map) do not. Indeed, you wouldn't really want to create a
map<double, intwith 1,000,000 identical elements.

Associative containers allocate nodes as needed. There is no need for
exponential memory reservation.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Nov 1 '06 #8
Pete Becker wrote:
loufoque wrote:
filox wrote:
that sounds like it could help. only, i don't know how to do it...
could you write an example how to call a constructor with a size of
,say, 100 bytes?
1) I already told you it is in constructor
2) If you have doubts you should check your reference documentation
3) It is the same syntax than with all other containers.

That's too broad. The standard sequence containers (vector, list, deque)
have constructors that initialize them with a specified number of
elements. The standard associative containers (set, multi_set, map,
multi_map) do not. Indeed, you wouldn't really want to create a
map<double, intwith 1,000,000 identical elements.
Moreover, you couldn't since a std::map's keys must be unique.
Associative containers allocate nodes as needed. There is no need for
exponential memory reservation.
Exactly. The resize member function for the SGI's hash_map
(http://www.sgi.com/tech/stl/HashedAs...Container.html) and the
constructor for SGI's and TR1's
(http://www.open-std.org/jtc1/sc22/wg...2005/n1836.pdf)
hash maps both accept a parameter specifying number of buckets (which
has to do with look-up speed), not number of allocated/reserved pairs.

Cheers! --M

Nov 1 '06 #9
mlimber wrote:
Pete Becker wrote:
>loufoque wrote:
>>filox wrote:

that sounds like it could help. only, i don't know how to do it...
could you write an example how to call a constructor with a size of
,say, 100 bytes?
1) I already told you it is in constructor
2) If you have doubts you should check your reference documentation
3) It is the same syntax than with all other containers.
That's too broad. The standard sequence containers (vector, list, deque)
have constructors that initialize them with a specified number of
elements. The standard associative containers (set, multi_set, map,
multi_map) do not. Indeed, you wouldn't really want to create a
map<double, intwith 1,000,000 identical elements.

Moreover, you couldn't since a std::map's keys must be unique.
<gThat should have been multi_map.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Nov 1 '06 #10
"mlimber" <ml*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
filox wrote:
>"mlimber" <ml*****@gmail.comwrote
How do you know it takes 70 MB?

because the windows task manager says so...
>>From what I've read, the Task Manager is not a trustworthy source of
information on this count. Ask about reliable ways to calculate memory
usage in a Windows newsgroup, and once you are confident in the
numbers, ask here again if necessary.

Cheers! --M
i'm confident in the numbers...
Nov 2 '06 #11
filox wrote:
"mlimber" <ml*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>filox wrote:
>>"mlimber" <ml*****@gmail.comwrote
How do you know it takes 70 MB?
because the windows task manager says so...
From what I've read, the Task Manager is not a trustworthy source of
information on this count. Ask about reliable ways to calculate memory
usage in a Windows newsgroup, and once you are confident in the
numbers, ask here again if necessary.

i'm confident in the numbers...
The numbers are right, but they're not saying what you think they're
saying. The task manager tells you the total amount of memory currently
assigned to each task. When you do a bunch of allocations the OS may
have to give the task more memory. The amount it gives the task will be
at least as much as the task has asked for, but it may be more, too.
Unless you know the details of how the OS decides to divvy up memory,
there's not much you can conclude about actual memory use from looking
at this number. The time to worry is if you've allocated 70MB and the
task manager says you have 10MB.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Nov 2 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: pembed2003 | last post by:
Hi All, Does C++/STL have hashtable where I can do stuff like: Hashtable h<int>; h.store("one",1); h.store("two",2); and then later retrieve them like:
12
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the...
6
by: thecodemachine | last post by:
Hi, I'm looking for a fast and simple one to one hash function, suitable for longer strings (up to 2048 in length). I'd like keys to be relatively short, I doubt I'd be creating more than 256...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
4
by: MS | last post by:
Hi, I'm writing a PHP login script for a web site. I've looked at several examples on the web and some of them use MD5 hashes for the password. They do this in various ways. EG. a) Storing...
6
by: j1mb0jay | last post by:
I am currently working on a dictionary populating program. I currently have a socket connection my local news server and am trawling through all of the articles looking for new words. I am...
24
by: Alexander Mahone | last post by:
Hello, I'm looking for an hash function to be used for an hash table that will contain structs of a certain kind. I've looked into Sourceforge.net, but so far I've found only hash functions for...
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
11
by: JWest46088 | last post by:
I'm having difficulty trying to figure out how to print a text file from a hash table one line at a time. I have the text file read into the hash table and can print the text file all at once, but I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.