#include <new>#include <iostream>class T{ int f; int g; int k;};int main(int argc, char *argv[]){ std::cout << sizeof(int); int count = 0; try { forever { [b]double* p = new double;[/b] count++; if (!(count % 1000000)) { std::cout << count << "\n"; } } } catch(std::bad_alloc &ba) { std::cout << "bad_alloc "; std::cout << count; } catch(...) { std::cout << "unknown " << count; }}
C++ (Qt)#include <new>#include <iostream> template<typename T>void func(){ std::cout << "size type: " << sizeof( T ) << std::endl; T *p1 = new T; std::cout << p1 << std::endl; T *p2 = new T; std::cout << p2 << std::endl; std::cout << "size block: " << ((char*)p2 - (char*)p1) << std::endl;} struct Type1{ int a; int b; int c; int d; int e;}; struct Type2{ double a; double b; double c; double d; double e;}; int main( int argc, char *argv[] ){ func<int>(); std::cout << "------" << std::endl; func<double>(); std::cout << "------" << std::endl; func<Type1>(); std::cout << "------" << std::endl; func<Type2>();}
#include <QList>#include <new>#include <iostream>struct Type1{ double a; double b; double c; double d; double e;}; struct Type2{ double a; double b; double c; double d; double e; double f;};class T{ double f; double g; double h; double d; int k;};int main(int argc, char *argv[]){ //std::cout << sizeof(T); forever { int count = 0; QList<void*> pointers; try { forever { Type1* p1 = new Type1; Type2* p2 = new Type2; T* p3 = new T; delete p1; delete p3; pointers.append(p2); count++; if (!(count % 1000000)) { std::cout << count << "\n"; } } } catch(std::bad_alloc &ba) { std::cout << "bad_alloc "; std::cout << count; std::cout << "\n"; foreach(void* p, pointers) { delete p; } pointers.clear(); } catch(...) { std::cout << "unknown " << count; } }}