egcs-1.1a: new don't not throw bad_alloc

Ryszard Kabatek rysio@rumcajs.chemie.uni-halle.de
Fri Sep 11 04:04:00 GMT 1998


I tested the behaviour of 'new' again.
If the size of the array is smaller then INT_MAX-11 (?),
'new' does throw bad_alloc.
If it's INT_MAX-10 or more 'new' does not throw.

My configuration:
Linux (RedHat 5.1), Pentium II
265 MB RAM
2x128MB swap


// sample.cc
# include <iostream.h>
# include <exception>
# include <climits>

int main()
{
  try {
     char* p = new char[INT_MAX-10];
     p[1000] = 'x';
     delete [] p;
  }
  catch (exception& exc) {
     cerr << exc.what() << '\n';
  }
}


Ryszard Kabatek

Martin-Luther University Halle-Wittenberg
Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 Fax. +49 3461 46 2129
e-mail: kabatek@chemie.uni-halle.de




More information about the Gcc mailing list