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"); }
C++ (Qt)l.length() == 300000000 -1
QString &QString::append(const QString &str)1871 {1872 if (str.d != Data::sharedNull()) {1873 if (d == Data::sharedNull()) {1874 operator=(str);1875 } else {1876 if (d->ref.isShared() || uint(d->size + str.d->size) + 1u > d->alloc)1877 reallocData(uint(d->size + str.d->size) + 1u, true);1878 memcpy(d->data() + d->size, str.d->data(), str.d->size * sizeof(QChar));1879 d->size += str.d->size;1880 d->data()[d->size] = '\0';1881 }1882 }1883 return *this;1884 }
int qAllocMore(int alloc, int extra){ Q_ASSERT(alloc >= 0 && extra >= 0); Q_ASSERT(alloc < (1 << 30) - extra); unsigned nalloc = alloc + extra; // Round up to next power of 2 // Assuming container is growing, always overshoot //--nalloc; nalloc |= nalloc >> 1; nalloc |= nalloc >> 2; nalloc |= nalloc >> 4; nalloc |= nalloc >> 8; nalloc |= nalloc >> 16; ++nalloc; Q_ASSERT(nalloc > unsigned(alloc + extra)); return nalloc - extra;}