Unordered map copy segfaults! (STL map does not)
Hi everyone,
When I copy an unordered map, it segfaults. I am not having the same problem
with STL's map. Using an unordered map is essential for performance, so I
would really appreciate any help! Any ideas?
Here are the details:
================
typedef boost::unordered_map
MeMooMeM wrote:
Here are the details: ================
typedef boost::unordered_map
MyMap; MyMap a; ... ... // (I populate map 'a' here in a loop) ... MyMap b;
b = a; // Segfaults! (also, I do not want to initialize b with a as in MyMap b(a), I want to copy it later in the code.)
You should write a proper testcase and provide your platform, so that people have a chance to reproduce your results.
Mathias Gaunard-2 wrote:
You should write a proper testcase and provide your platform, so that people have a chance to reproduce your results.
That's right. I prepared a toy code as you suggested, but it works just fine (?!). When I use the same structure inside my code, it segfaults. It is most probably due to some messed up memory section. Still it is strange that I get no segfaults (also no detected errors by valgrind) using STL's map... Everyone, please ignore this post until I find a proper way to demonstrate the problem. Thanks! -- View this message in context: http://www.nabble.com/Unordered-map-copy-segfaults%21-%28STL-map-does-not%29... Sent from the Boost - Users mailing list archive at Nabble.com.
MeMooMeM wrote:
Mathias Gaunard-2 wrote:
You should write a proper testcase and provide your platform, so that people have a chance to reproduce your results.
That's right. I prepared a toy code as you suggested, but it works just fine (?!). When I use the same structure inside my code, it segfaults. It is most probably due to some messed up memory section. Still it is strange that I get no segfaults (also no detected errors by valgrind) using STL's map...
Everyone, please ignore this post until I find a proper way to demonstrate the problem.
Thanks!
OK, mystery is solved. Here's what happened, in case someone else has this problem: I was *not* using the standard for loop, as in: for (Map_t::iterator it = somemap.begin(); it != somemap.end(); it++) because I was erasing elements from the map, which is known to mess things up if a for loop is being used. Instead, I was using a while loop and incrementing the iterator in a more controlled way: somemap.erase(it++); which erases the element but still returns correclty incremented iterator. However forgot to check for the case: (it++ == somemap.end()) in the while loop, hence the segmentation faults. Thanks again! -- View this message in context: http://www.nabble.com/Unordered-map-copy-segfaults%21-%28STL-map-does-not%29... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
Mathias Gaunard
-
MeMooMeM