1 / 2
Dec 2004

I have gleaned that parts of the STL can throw this, I was wondering if anyone had any more information. One of my programs is doing this:

map<string,int> foo;
loop10ktimes {
 foo[somestring]=someint;
}
loop10ktimes {
 someint=foo[somestring]; //string is known good key for map
}

and its throwing a SIGABRT at me. aside from the above the only things I am using are cin, cout, string, printf, and scanf, so I am pretty sure the problem is with the map. 10000 ints and short strings shouldnt be using up too much memory, right? any pointers would be helpful.

  • created

    Dec '04
  • last reply

    Jan '05
  • 1

    reply

  • 822

    views

  • 2

    users

[quote="sparr0"]I have gleaned that parts of the STL can throw this, I was wondering if anyone had any more information. One of my programs is doing this:

map<string,int> foo;
loop10ktimes {
 foo[somestring]=someint;
}
loop10ktimes {
 someint=foo[somestring]; //string is known good key for map
}

and its throwing a SIGABRT at me. aside from the above the only things I am using are cin, cout, string, printf, and scanf, so I am pretty sure the problem is with the map. 10000 ints and short strings shouldnt be using up too much memory, right? any pointers would be helpful.[/quote]
Well.. your solution clearly runs out of memory; just look at the measured memory consumption: it is 255872KB, and the hard-limit is 256MB.

STL couldn't really be that bad, but I wrote this little program:

#include <string>
#include <map>
using namespace std;
map<string,int> foo;
int main() {
	string s("a");
	for(int i=0; i<10000; i++) {
		foo[s]=666;
		int p=s.size()-1;
		s[p]++;
		while(p>0 && s[p]>'z') {
			s[p--]='a';
			s[p]++;
		}
		if (p==0 && s[0]>'z') {
			s[0]='a';
			s.insert(0,"a");
		}
	}
}

It runs fine and spoj says it needed 2676KB, which is fine by me (string-map "hello world" was 2388KB).

Your strings are probably not that short stuck_out_tongue

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 6d

Want to read more? Browse other topics in C and C++ or view latest topics.