app crash when there's more than 3000 entries in std::map ?

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hi everyone

I have this strange behaviour happening with this code which I can't
explain. On my computer when I set nt with a value greater than 3000
it crashes. Is there a max number of keys I can use with a std::map ?

thanks a lot

#include <vector>
#include <iostream>
#include <map>

#include <string>


int main()
{
	float t = clock();
	int nt = 3000;
#if 1
	hash_map<std::string, int, hash<std::string> > mymap;
	for ( int i = 0; i < nt; ++i )
	{
		string tmp = "test" + i;
		mymap[ tmp ] = i;
	}
	for ( int i = 0; i < 10e5; ++i )
	{
		int a = (int)(drand48() * nt);
		string tmp = "test" + a;
		hash_map<std::string, int, hash<std::string> >::iterator it =
mymap.find( tmp );
		if ( it != mymap.end() )
		{
		}
		else
		{
			printf("not found\n");
		}
	}
	unsigned max_size = mymap.max_size();
	printf("%d\n", max_size );

#else
	std::map<std::string, int> mymap;
	for ( int i = 0; i < nt; ++i )
	{
		string tmp = "test" + i;
		mymap[ tmp ] = i;
	}
	for ( int i = 0; i < 10e5; ++i )
	{
		int a = (int)(drand48() * nt);
		string tmp = "test" + a;
		std::map<std::string, int>::iterator it = mymap.find( tmp );
		if ( it != mymap.end() )
		{
		}
		else
		{
			printf("not found\n");
		}
	}

	unsigned max_size = mymap.max_size();
	printf("%d\n", max_size );

#endif
	printf("time %f\n", (clock() - t ) / float( CLOCKS_PER_SEC ) );

	return 0;
}

#endif
0
Reply mast4as (90) 8/12/2010 5:33:22 PM

See related articles to this posting


Sorry you need to add

#include <ext/hash_map>
using namespace __gnu_cxx;
namespace __gnu_cxx {

// hash specialisation to allow hashing of strings
template<>
struct hash<std::string>
{
	size_t operator()(const std::string &__s) const { return
__stl_hash_string(__s.c_str()); }
};

} // namespace __gnu_cxx OR std

at the top if you want this to compile. But hash_map and map behaves
the same

using c++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
On Aug 12, 6:33=A0pm, mast4as <mast...@yahoo.com> wrote:
> Hi everyone
>
> I have this strange behaviour happening with this code which I can't
> explain. On my computer when I set nt with a value greater than 3000
> it crashes. Is there a max number of keys I can use with a std::map ?
>
> thanks a lot
>
> #include <vector>
> #include <iostream>
> #include <map>
>
> #include <string>
>
> int main()
> {
> =A0 =A0 =A0 =A0 float t =3D clock();
> =A0 =A0 =A0 =A0 int nt =3D 3000;
> #if 1
> =A0 =A0 =A0 =A0 hash_map<std::string, int, hash<std::string> > mymap;
> =A0 =A0 =A0 =A0 for ( int i =3D 0; i < nt; ++i )
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string tmp =3D "test" + i;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mymap[ tmp ] =3D i;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 for ( int i =3D 0; i < 10e5; ++i )
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int a =3D (int)(drand48() * nt);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string tmp =3D "test" + a;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 hash_map<std::string, int, hash<std::stri=
ng> >::iterator it =3D
> mymap.find( tmp );
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ( it !=3D mymap.end() )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("not found\n");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 unsigned max_size =3D mymap.max_size();
> =A0 =A0 =A0 =A0 printf("%d\n", max_size );
>
> #else
> =A0 =A0 =A0 =A0 std::map<std::string, int> mymap;
> =A0 =A0 =A0 =A0 for ( int i =3D 0; i < nt; ++i )
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string tmp =3D "test" + i;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 mymap[ tmp ] =3D i;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 for ( int i =3D 0; i < 10e5; ++i )
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int a =3D (int)(drand48() * nt);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string tmp =3D "test" + a;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 std::map<std::string, int>::iterator it =
=3D mymap.find( tmp );
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ( it !=3D mymap.end() )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("not found\n");
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
>
> =A0 =A0 =A0 =A0 unsigned max_size =3D mymap.max_size();
> =A0 =A0 =A0 =A0 printf("%d\n", max_size );
>
> #endif
> =A0 =A0 =A0 =A0 printf("time %f\n", (clock() - t ) / float( CLOCKS_PER_SE=
C ) );
>
> =A0 =A0 =A0 =A0 return 0;
>
> }
>
> #endif

0
Reply mast4as (90) 8/12/2010 5:34:57 PM

On Aug 12, 12:33=A0pm, mast4as <mast...@yahoo.com> wrote:
> Hi everyone
>
> I have this strange behaviour happening with this code which I can't
> explain. On my computer when I set nt with a value greater than 3000
> it crashes. Is there a max number of keys I can use with a std::map ?
>

It's because this doesn't do what you think it does:

> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string tmp =3D "test" + i;

It does *not* make a string named "test1", "test2", etc.
Instead, it does pointer arithmetic on the const char*
that points to "test".

So
   ("test" + 0) is a pointer to the string "test"
   ("test" + 1) is a pointer to the string "est"
   ("test" + 2) is a pointer to the string "st"

etc.

Once i passes the null byte in the string literal, though,
you're into some random chunk of memory. All bets are off.
Eventually you're reading outside of memory that belongs
to your application and you get a segfault.

--Jonathan
0
Reply jonathan.lee.975 (40) 8/12/2010 5:49:01 PM

On Aug 12, 6:49=A0pm, Jonathan Lee <jonathan.lee....@gmail.com> wrote:
> On Aug 12, 12:33=A0pm, mast4as <mast...@yahoo.com> wrote:
>
> > Hi everyone
>
> > I have this strange behaviour happening with this code which I can't
> > explain. On my computer when I set nt with a value greater than 3000
> > it crashes. Is there a max number of keys I can use with a std::map ?
>
> It's because this doesn't do what you think it does:
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string tmp =3D "test" + i;
>
> It does *not* make a string named "test1", "test2", etc.
> Instead, it does pointer arithmetic on the const char*
> that points to "test".
>
> So
> =A0 =A0("test" + 0) is a pointer to the string "test"
> =A0 =A0("test" + 1) is a pointer to the string "est"
> =A0 =A0("test" + 2) is a pointer to the string "st"
>
> etc.
>
> Once i passes the null byte in the string literal, though,
> you're into some random chunk of memory. All bets are off.
> Eventually you're reading outside of memory that belongs
> to your application and you get a segfault.
>
> --Jonathan

Thanks a lot yes ... I just figured (long day at work ;-(

Thank you so much
std::string createRandomString()
{
	char alpha[ 6 ] =3D { 'a', 'b', 'c', 'd', 'e', 'f' };
	char str[ 10 ];
	for ( int i =3D 0 ; i < 10 ; i++ )
	{
		int a =3D int(drand48()*5);
		str[ i ] =3D a;
	}
	return std::string( str );
}

int main()
{
	float t =3D clock();
	int nt =3D 10000;
#if 1
	hash_map<std::string, int, hash<std::string> > mymap;
	for ( int i =3D 0; i < nt; ++i )
	{
		string tmp =3D createRandomString();
		mymap[ tmp ] =3D i;
	}
	for ( int i =3D 0; i < 10e5; ++i )
	{
		int a =3D (int)(drand48() * nt);
		string tmp =3D createRandomString();
		hash_map<std::string, int, hash<std::string> >::iterator it =3D
mymap.find( tmp );
		if ( it !=3D mymap.end() )
		{
		}
		else
		{
			//printf("not found\n");
		}
	}
	unsigned max_size =3D mymap.max_size();
	printf("%d\n", max_size );

#else
	std::map<std::string, int> mymap;
	for ( int i =3D 0; i < nt; ++i )
	{
		string tmp =3D createRandomString();
		mymap[ tmp ] =3D i;
	}
	for ( int i =3D 0; i < 10e5; ++i )
	{
		int a =3D (int)(drand48() * nt);
		string tmp =3D createRandomString();
		std::map<std::string, int>::iterator it =3D mymap.find( tmp );
		if ( it !=3D mymap.end() )
		{
		}
		else
		{
			//printf("not found\n");
		}
	}

	unsigned max_size =3D mymap.max_size();
	printf("%d\n", max_size );

#endif
	printf("time %f\n", (clock() - t ) / float( CLOCKS_PER_SEC ) );

	return 0;
}

#endif
0
Reply mast4as (90) 8/12/2010 5:56:03 PM

On Aug 12, 12:56=A0pm, mast4as <mast...@yahoo.com> wrote:
> Thanks a lot yes ... I just figured (long day at work ;-(
>
> Thank you so much
> std::string createRandomString()
> {
> =A0 =A0 =A0 =A0 char alpha[ 6 ] =3D { 'a', 'b', 'c', 'd', 'e', 'f' };
> =A0 =A0 =A0 =A0 char str[ 10 ];
> =A0 =A0 =A0 =A0 for ( int i =3D 0 ; i < 10 ; i++ )
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int a =3D int(drand48()*5);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 str[ i ] =3D a;
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 return std::string( str );
>
> }

No problem. BTW, if you want to avoid these random strings
you could probably use next_permutation from <algorithm>
to get some string names. Make a char array of distinct
letters, permute them, and use string::append to get your
dummy string.

(Not entirely related, just something I've found useful
before)

--Jonathan
0
Reply jonathan.lee.975 (40) 8/12/2010 6:03:14 PM
comp.lang.c++ 48321 articles. 29 followers. Post

4 Replies
158 Views

Similar Articles

[PageSpeed] 24


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

app crash when there's more than 3000 entries in std::map ?
Hi everyone I have this strange behaviour happening with this code which I can't explain. On my computer when I set nt with a value greater than 3000 it crashes. Is there a max number of keys I can use with a std::map ? thanks a lot #include <vector> #include <iostream> #include <map> #include <string> int main() { float t = clock(); int nt = 3000; #if 1 hash_map<std::string, int, hash<std::string> > mymap; for ( int i = 0; i < nt; ++i ) { string tmp = "test" + i; mymap[ tmp ] = i; } for ( int i = 0...

bogus entries in map (std library)
Hi, I am getting zero as value for some keys in my map which can never happen as per my understanding of my code. These are the details: I have defined an array of vectors, where each vector element is a map, like this: vector<map<string,int> entry>* fulldata ; using new operator, fulldata is memory allocated and each vector's size is made 10 by calling resize() function. The maps are always updated using ++fulldata[i][j][key_string]; This means that no key_string in the map can have corresponding zero integer values. But I get bogus entries in some maps with 0 values ...

check for deleted map entry -> crash ?
I'm using an STL map in my code. My application sometimes tries to delete things twice from the map. This leads to a crash in my current code. The problem is probably the way I check whether it is necessary to delete something (line 44 and 52 in below code). In the below code the problem is demonstrated, line 65 will cause a segmentation fault. 1 #include <iostream> 2 #include <cstdlib> 3 #include <map> 4 5 using namespace std; 6 7 class MyClass 8 { 9 public: 10 MyClass(int); 11 ~MyClass(); 12 void...

std::map and custom key class, find returns first entry no matter what???
I've got this std::map that has got a custom class as the key, I've overloaded the < operator but fin() returns "mambo jambo" value (probably consistent the FIRST value) code: std::map<private_::MessageCommand, itsVoidFunction>::iterator funcIterThis = itsMessageMapThis.find(com); // This one allways kicks in ?!? if( funcIterThis != itsMessageMapThis.end() ) //MessageMap class < operator bool operator < ( const MessageCommand & left, const MessageCommand & right ) { if( left.Msg > right.Msg ) return false; if( left.WPa...

std::maps within std::maps -- optimisation
Here's a small example which uses std::maps within std::maps. Note the line flagged // *** copy? #include <iostream> #include <map> #include <string> struct Tfoo { Tfoo():i1_(0),i2_(0){} Tfoo(int i1, int i2):i1_(i1),i2_(i2){} int i1_; int i2_; }; typedef std::map<std::string, Tfoo> TfooMapInner; typedef std::map<std::string, TfooMapInner> TfooMapOuter; int main(int argc, char **argv) { TfooMapOuter myFooMapOuter; { TfooMapInner myFooMapInner; myFooMapInner["inner_key_1"] = Tfoo(0,1); myFooMapInner["inner_key_...

Problems with std::map.insert() and std::map.find()
I have written a class template to store manage/raw pointers, I want to store pointers to an obects, using a key. I find that find() is not working (after the first insert) - i.e. once the first item is inserted in the map, any key passed to the find() method will return the first item. Additionally, once the first item has been stored, no additional items can be stored - its driving me nuts, and I cant work outt why this is happening. I have included both my classes (i.e class template and key class here - hopefully, someone can spot what is causing things to go awry). To summarize th...

std::transform for std::map
Hi, it doesn't seem to be possible to use transform for maps. #include <algorithm> #include <map> #include <iterator> #include <vector> #include <iostream> using namespace std; int doit(int w) { return w+1; } int main() { map<int,int> m; vector<int> v; m[0]=42; v.push_back(42); //transform(m.begin(),m.end(),m.begin(),doit); (*) transform(v.begin(),v.end(),v.begin(),doit); copy(v.begin(),v.end(),ostream_iterator<int>(cout," ")); cout<<endl; } I understand syntactically why the line (*) ...

Clarification for std::vector and std::map
Can someone explain what is happening in the following code? #include <iostream> #include <vector> #include <map> using namespace std; int main() { vector<int> v; map<char*,int*> m; v.push_back(99); m["TEST"]=&v[0]; cout<<"Vec size: "<<v.size()<<" : "<<v[0]<<endl; v.erase(&v[0]); cout<<"Map: "<<*m["TEST"]<<endl; cout<<"Vec size: "<<v.size()<<endl; return 0;...

std::valarray as value in std::map
Hello group, g++ (3.4.2, mingw): float init[] = {1.f, 2.f, 3.f}; std::map<std::string, std::valarray<float> > mp; mp["name"] = std::valarray(init, 3); mp["name"].size(); // should be 3, but IS 0! Do i ignored something? Does map not do a copy of value? HAND, Chris Chris Forone schrieb: > Hello group, > > g++ (3.4.2, mingw): > > float init[] = {1.f, 2.f, 3.f}; > std::map<std::string, std::valarray<float> > mp; > > mp["name"] = std::valarray(init, 3); > mp["name"].size(); // should be 3, but IS 0!...

using std::find_if() with a std::map
I have map variable that maps ids (unsigned int) to objects. Each object has a Name() method. I want to use std::find_if to fetch the object that name matches. I defined my predicate like this: class NameMatch { public: inline NameMatch ( const std::string& name ) : m_name ( name ) {} inline bool operator() ( const char* systemname ) const { return !stricmp(m_name.c_str(), systemname) ; } inline ~NameMatch(){} private: std::string m_name ; }; I got the ff error: error C2664: 'bool `anonymous-namespace'::NameMatch::operator ()(const char *) const' : can...

How to use std::copy with std::map?
Should the following work? It does on some compilers. How can I get it to work on g++ 3.2? On g++ 3.2 it keeps telling me that there is no such function operator << for ostream and pair<string,string>. But there is! And I can call it! And it works! So why cannot std::copy find it? thanks, Siegfried template<typename K, typename V> ostream& operator<<(ostream& os, std::pair<K,V>& p){ return os << p.first << p.second; } std::map<string,string> m; m[(string)"hello"] = (string)"there"; std::copy(m.begin(), m.end(...

Which container
I am wriing a messaging system and I need to mantain a list of subscribers(object) to topics (string). which of the ff representations is better (and why?) typedef pair<string, list<Subscriber> > topicSubscribers ; typedef list<topicSubscribers> subscriberList ; OR typedef map<string, list<Subscriber> > topicSubscribers ; typedef list<topicSubscribers> subscriberList ; Bart Simpson <eatmyshorts@springfield.com> wrote: > which of the ff representations is better (and why?) > > typedef pair<string, list<Subscriber> > topicSub...

Which Crashes More? Apple Apps or Android Apps?
<http://www.pcmag.com/article2/0,2817,2399852,00.asp> <quote> A new report from the crash report analytics company Crittercism indicates that iOS apps tend to crash more than Android apps. But are the numbers truly indicative of an Apple issue, or are they typical of what one might see in the app landscape shortly after a major iOS release? Crittercism's crash survey analyzed more than 214 million different app launches between November and December of 2011 to determine the source of most app crashes. And, in doing so, the company came up with the statistic that more iOS apps...

Implementing GO4's Observer pattern for std::stirng and std::vector/std::map
Hi, I want to "observe" changes to std::string and std::vector/std::map structures. The idea being that whenever code modifies a string, or adds/deletes a collection element, my code is notified so that I can invalidate view objects, etc. I know that I can wrap these data structures within my own classes and add the observer hooks to my accessor routines. This is a tedious and error-prone process for things like std::string with lots of methods. I'm curious if others have found a good way to do this for STL strings and containers. All my reading warns against su...

std::map<int,std::set<std::string> > Wrong? (Segmentation fault.)
Hello, I have the following code: std::map<int,std::set<std::string> > k; k[0]="1234567890"; k[1]="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k) throw(std::runtime_error) { std::map<int,std::set<std::string> >::const_iterator i; i=k.find(0); if(i==k.end()) throw std::runtime_error("No zero in k."); return i->second; } Compilation of this code goes well, but I have the following problem while executing this in my implementation: "Segmentation fault". I have pi...

Initialize a std::set with keys from a std::map
A portion of my program needs to initialize a std::set<int> to have all the keys in a std::map<int, double>. The code I've pasted below works, but I'm wondering if there's a more elegant way to do it (an STL algorithm, maybe?). I'm a bit of an STL noob, so any advice people can give would be greatly appreciated. typedef std::map<int, double> intDoubleMap; typedef std::set<int> intSet; intSet v; // map is an intDoubleMap* and has been initialized with some values for (intDoubleMap::const_iterator it = map->begin(); it != map->end(); ...

PCLinuxOS: app crashes --> system crashes
"When I'm trying to burn a DVD or CD in both K3b and Brasero when i get to the point "sending cue sheet" my laptop freezes and shortly after the PC crashes (shutdown)." http://www.pclinuxos.com/index.php?option=com_smf&Itemid=58&topic=42163.0 ...

a new wiki entry -- mapped entry fields ...
By way of thanks to the Tcl community for 8.5.0 and all the help I've gotten over the years, I've added a wiki entry to put up a very simple, but hopefully useful poor man's field validation template. It is not much, but hopefully it may prove useful to those who need a dirt simple entry mapping facility ... http://wiki.tcl.tk/20610 Oh, the namespace (de) is for 'data entry' 8-). template: 9 - a numeric A - an alpha X - an alpha numeric ? - any other character is a literal. # sample usage ... package require Tk package require Ttk ttk::entry ...

naming folders from within apps crashes the apps
If I create and name a folder from within an application--for example, while downloading a file--the application crashes when I or it tries to utilize the folder. When I then look at the folder again, whether from the application or from Windows Explorer, I discover that the name I'd given to the folder didn't "take". If I use Windows Explorer to create and name the folder, the app doesn't crash. The os is Windows 98. Thank you! In <DP3jb.780194$uu5.136574@sccrnsc04> Howard J <bikepathlesstaken@yahoo.com> wrote: > If I create and name a fo...

What's the different between std::multimap<key, value> and std::map<key, std::set<value> >
I found that they have one key and multiple values which is unique. Anyone supplement=EF=BC=9F This is a MIME GnuPG-signed message. If you see this text, it means that your E-mail or Usenet software does not support MIME signed messages. The Internet standard for MIME PGP messages, RFC 2015, was published in 1996. To open this message correctly you will need to install E-mail or Usenet software that supports modern Internet standards. --=_mimegpg-monster.email-scan.com-6154-1324555502-0001 Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 Content-Transfer-Encoding: quoted-pr...

the last element in a container, (std::vector, std:map ... )
Hi, Using a vector as a example, if I have a something like: std::vector<int> myNumbers; // ... add items to the vector and I iterate thru them all, for( std::vector<int>::const_iterator it = myNumbers.begin(); it != myNumbers.end(); ++it ) { if( it == myNumbers.begin() ) { // do some stuff with the first element } else if( it == /* last element in the container */ ) // <------ { // do something because this is the last element. } else { // do something else for elements that are neither first nor last. } } In the cod...

Iterating a std::vector vs iterating a std::map?
I have a std::vector and a std::map containing the same number of elements. Currently I experience that iterating all elements in the map is slower that iterating all elements in the vector. Is this true ? carl wrote: > I have a std::vector and a std::map containing the same number of > elements. Currently I experience that iterating all elements in the map > is slower that iterating all elements in the vector. Is this true ? Do you want us to decide if you are hallucinating or not? You have said: you are experiencing it. So I guess then it is true. :) If your ...

searching keys in std::map using map::upper_bound
Hi, let's say I have a std::map<std::string,int> and I want to search the map for all keys that start with "foo". The regexp equivalent is to search for "foo*", or perhaps "^foo*". At present I do this quick'n'dirty by appending a tilde (~) to the query term, since I know it's last in the ascii table and my keys don't include any special characters. So to find everything that starts with "foo" I search the map from map::lower_bound("foo") to map::upper_bound("foo~"). See below for complete program that dem...

searching keys in std::map using map::upper_bound
Hi, I posted this in c.l.c++ a few days ago and didn't get a response, so I'm trying here instead. Let's say I have a std::map<std::string,int> and I want to search the map for all keys that start with "foo". The regexp equivalent is to search for "foo*", or perhaps "^foo*". At present I do this quick'n'dirty by appending a tilde (~) to the query term, since I know it's last in the ascii table and my keys don't include any special characters. So to find everything that starts with "foo" I search the map from map::lowe...

std::map::find() throws exception when map is empty?
Hello, std::map< int, MyClass*> mymap; it = mymap.find( somekey ) // here happen bad things if( it != mymap.end() ) { // do something useful with it->second } else { // do nothing } I traced a strange program crash (unhandled exception on windows, something similar on Solaris) down to happen at the second line of the code given above which contains the find(). After some investigation I found out that it happens when the map is empty. This behaviour could be reproduced on Windows 2k and XP using MSVC 6.0 and 7.0 and finally also on Solaris unsing the Sun CC 5.4. I read the docum...