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; 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