#include #include #include #include #include #include int main(int argc, char** argv) { long m, n; if (argc < 3) { std::cerr << argv[0] << " m n" << std::endl; exit(-1); } m = atol(argv[1]); n = atol(argv[2]); struct rlimit rl; if (getrlimit(RLIMIT_AS, &rl) >= 0) { std::cout << " Current limit = " << rl.rlim_cur << std::endl << " Maximum limit = " << rl.rlim_max << std::endl << " Infinity = " << RLIM_INFINITY << std::endl; } std::cout << " m = " << m << " n = " << n << " GBytes = " << m * n * sizeof(double)/(1024.0*1024.0*1024.0) << std::endl; try { double* y = (double*)malloc(m*n*sizeof(double)); if (y == NULL) throw std::bad_alloc(); std::fill(y, y + m*n, 1.0); std::cout << "Sleeping" << std::endl; sleep(10); free(y); // double* y = new double[m*n]; std::fill(y, y + m*n, 1.0); // std::cout << "Sleeping" << std::endl; // sleep(10); // delete[] y; } catch(std::bad_alloc& e) { std::cerr << "Bad alloc: " << e.what() << std::endl; } }