try { char * d = new char[1700000000]; for (int i= 0; i < 1700000000- 1; ++i) { d[i] = 1; } delete[] d; } catch(std::bad_alloc) { qDebug() << "bad_alloc"; }
try { QString l; while (l.length() < 300000000) { l.append("111111"); } } catch(std::bad_alloc) { qDebug() << "bad_alloc"; }
while (l.length() < 300000000) { l.append("111111"); }
while (l.length() < 300000000){ l.append("111111");}
C++ (Qt)#include <iostream>#include <QVector> using namespace std; int main(){ { cerr << "Allocate 1Gb" << endl; QVector<char> tst( 1024 * 1024 * 1024 ); } { cerr << "Allocate..." << endl; size_t it = 0; QVector<char> vec; QVector<char> chunk( 1024 * 1024 ); for(;;) { vec += chunk; cerr << it++ << " Mb" << endl; } }}