H.S. <hs**************@gmail.comwrote in message...
>
#include <iostream>
int main(){
// double *ldP;
size_t s = 2048*2048*58;
std::cout << "About to allocate " << s << " doubles" << std::endl;
// ldP = new double [s];
double *ldP( new double[ s ] );
delete [] ldP;
return 0;
}
$g++ -o testmem testmem.cc
$./testmem
About to allocate 243269632 doubles
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
thanks,
->HS
FYI: When you want a BIG number, try this:
// std::size_t big(-1); // compiler 'warning', but usually works (a)
int bigint(-1);
std::size_t big( bigint );
// #include <limits>
std::size_t big2( std::numeric_limits<std::size_t>::max() );
std::cout<<"size_t big()="<<big<<std::endl;
std::cout<<"size_t big2()="<<big2<<std::endl;
// out: size_t big()=4294967295
// out: size_t big2()=4294967295
Of course the '-1' trick (a) only works on 'unsigned' types
(, and may be UB on some systems (?)).
Use the 'numeric_limits<>' version.
--
Bob R
POVrookie