Topic: Guru of the Week #9: Solution


Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/05/14
Raw View
James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:

> >From discussions with Mike Ball (one of the implementers): Sun reserves
> a static block of memory for the exceptions, and obtains the necessary
> memory there.  When this block runs out, it aborts.
>
> I wonder what happens when I throw the following class:
>
>  struct SomeException { int a[ 1000000 ] ; } ;

I think this should be specified; some compilers allow the user
to change the size/allocate himself the static area but with
a different function/global in each compiler.

--

Valentin Bonnard
mailto:bonnardv@pratique.fr
http://www.pratique.fr/~bonnardv (Informations sur le C++ en Francais)
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: jpotter@falcon.lhup.edu (John Potter)
Date: 1997/05/14
Raw View
On 14 May 97 04:32:09 GMT, Valentin Bonnard wrote:

: James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:

: > >From discussions with Mike Ball (one of the implementers): Sun reserves
: > a static block of memory for the exceptions, and obtains the necessary
: > memory there.  When this block runs out, it aborts.
: >
: > I wonder what happens when I throw the following class:
: >
: >  struct SomeException { int a[ 1000000 ] ; } ;

: I think this should be specified; some compilers allow the user
: to change the size/allocate himself the static area but with
: a different function/global in each compiler.

FWIW, I tried the following on g++ and xlC on an RS6000 and Borland on
a pentium.  They all worked fine at 100000; however, Windows 95
crashed the 1M version.  On the RISC, I have a 32M stack; so, a 4M
throw is not that much if it is on the stack.  Just for fun, it was
caught by value.

John

#include <iostream.h>
int const BIG = 100000;
struct Biggie {
 int d[BIG];
 };
void tryBig () {
 Biggie b;
 cout << "We can allocate one on the stack (maybe)\n";
 for (int x = 0; x < BIG; ++ x)
  b.d[x] = 5;
 cout << "The space is somewhere\n";
 }
void tryBigThrow () {
 throw Biggie();
 }
int main () {
 tryBig();
 try {
  tryBigThrow();
  }
  catch (Biggie b) {
   cout << "We hit the catch\n";
   for (int x = 0; x < BIG; ++ x)
    b.d[x] = 5;
   cout << "And the space exists\n";
   }
 char ch;
 cin >> ch;
 return 0;
 }
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]