C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

hash_map creates access violation errors

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Rebecca Hoffmann
Guest





PostPosted: Tue Jun 07, 2005 1:14 pm    Post subject: hash_map creates access violation errors Reply with quote



hi,

I use a hash_map for storing 4x4 DCT-Blocks. Therefore I convert each
block into a string looking like:
":-88:-3:-9:-91:-44:1:-7:-93:88:-1:9:42:-2:-2:-6:". Then I use the
following code to identify blocks that have been seen before.


-- code -------------
std::hash_map<std::string, int> blockMap; //initialize hash_map
....

// add blockString to hashmap
if (blockMap[blockString] == NULL) {
blockMap[blockString] = ++blockIDcounter;
blockID = blockIDcounter;
} else {
blockID = blockMap[blockString];
}

-- end of code -------

The blockIDcounter counts the number of different blocks.

during calculation of the first image frame, there is always a runtime
error (access violation reading/writing to a certain address) when
reaching a blockIDcounter around 1800.

So, what could be the reason for this problem? I use Visual Studio C++
..NET 2003.


best regards,
Rebecca Hoffmann

--
[email]rebecca.hoffmann (AT) tut (DOT) fi[/email]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Thomas Maeder
Guest





PostPosted: Tue Jun 07, 2005 10:49 pm    Post subject: Re: hash_map creates access violation errors Reply with quote



[email]Rebecca.Hoffmann (AT) gmail (DOT) com[/email] (Rebecca Hoffmann) writes:

Quote:
I use a hash_map for storing 4x4 DCT-Blocks. Therefore I convert
each block into a string looking like:
":-88:-3:-9:-91:-44:1:-7:-93:88:-1:9:42:-2:-2:-6:". Then I use the
following code to identify blocks that have been seen before.


-- code -------------
std::hash_map<std::string, int> blockMap; //initialize hash_map
...

// add blockString to hashmap
if (blockMap[blockString] == NULL) {

Why NULL? The value type of blockMap is int, so why don't you write 0?


Quote:
blockMap[blockString] = ++blockIDcounter;
blockID = blockIDcounter;
} else {
blockID = blockMap[blockString];
}

-- end of code -------

The blockIDcounter counts the number of different blocks.

during calculation of the first image frame, there is always a
runtime error (access violation reading/writing to a certain
address) when reaching a blockIDcounter around 1800.

Please post the minimal (<50 lines) complete program that produces
this access violation so that your audience can see what you are
seeing.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Branimir Maksimovic
Guest





PostPosted: Thu Jun 09, 2005 3:44 pm    Post subject: Re: hash_map creates access violation errors Reply with quote



Rebecca Hoffmann wrote:
Quote:
hi,

-- code -------------
std::hash_map<std::string, int> blockMap; //initialize hash_map
...


during calculation of the first image frame, there is always a runtime
error (access violation reading/writing to a certain address) when
reaching a blockIDcounter around 1800.

So, what could be the reason for this problem? I use Visual Studio C++
.NET 2003.

First try with std::map, not hash_map. If map works and hash_map don't,
then default hash function for string probably doesn't work,
so you must provide your own hashing function (read the docs I guess).

Greetings, Bane.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Martin Bonner
Guest





PostPosted: Fri Jun 10, 2005 4:30 pm    Post subject: Re: hash_map creates access violation errors Reply with quote



Branimir Maksimovic wrote:
Quote:
Rebecca Hoffmann wrote:
hi,

-- code -------------
std::hash_map<std::string, int> blockMap; //initialize hash_map
...


during calculation of the first image frame, there is always a runtime
error (access violation reading/writing to a certain address) when
reaching a blockIDcounter around 1800.

So, what could be the reason for this problem? I use Visual Studio C++
.NET 2003.

First try with std::map, not hash_map. If map works and hash_map don't,
then default hash function for string probably doesn't work,
so you must provide your own hashing function (read the docs I guess).

That seems unlikely. If the hash function is poor (eg "hash() { return
0; }" ) then the performance of the hash_map will be appalling, but the
behaviour should be the same.

It looks to me like there is some memory corruption going on somewhere,
or indirection through an invalidated iterator, or something similar.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.