 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Rebecca Hoffmann Guest
|
Posted: Tue Jun 07, 2005 1:14 pm Post subject: hash_map creates access violation errors |
|
|
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
|
Posted: Tue Jun 07, 2005 10:49 pm Post subject: Re: hash_map creates access violation errors |
|
|
[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
|
Posted: Thu Jun 09, 2005 3:44 pm Post subject: Re: hash_map creates access violation errors |
|
|
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
|
Posted: Fri Jun 10, 2005 4:30 pm Post subject: Re: hash_map creates access violation errors |
|
|
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 |
|
 |
|
|
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
|
|