When I try to resize the list the program crashes… Look at that code, try to enter 1,000,000,000 (10^9)… On my windows 7 x64 doesnt work.
#include <cstdlib>
#include <iostream>
#include <list>
using namespace std;
int main(int argc, char *argv[])
{
list<long long> l;
long long n;
cin>>n;
cout<<l.max_size()<<endl;
//uncomment 1 or 2
//l.resize(n,l.size()+1); //1st try
/*for (long long i=0; i<n; i++) //2nd try
l.push_back(n);*/
//system("PAUSE"); // uncomment if needed
return 0;
}
The max size is over 4*10^9, but still doesnt work… Im using the newest MinGW (G++)
Since “available memory” is a slightly fickle concept,
l.max_size()returns a hard maximum. Your “crash” is very likely an uncaughtstd::bad_alloc, which you’d expect when running out of memory.