www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/13/11:33:50

From: "Paul Derbyshire" <pderbysh AT usa DOT net>
Newsgroups: comp.os.msdos.djgpp
References: <35594e81 DOT 4169631 AT 192 DOT 168 DOT 1 DOT 250> <8uh61.2667$z15 DOT 2572850 AT news21 DOT bellglobal DOT com> <35599b32 DOT 1408551 AT 192 DOT 168 DOT 1 DOT 250>
Subject: Re: What does new do when memory is exhausted?
Lines: 49
Organization: The Chaos Zone
MIME-Version: 1.0
Message-ID: <NRi61.3175$z15.2638980@news21.bellglobal.com>
Date: Wed, 13 May 1998 15:19:09 GMT
NNTP-Posting-Host: 206.172.228.122
NNTP-Posting-Date: Wed, 13 May 1998 11:19:09 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>Is it possible to set this up to be the default behavior my modifying
>some startup file or other? So you don't have to keep doing it in
>every program?

Yes and no...

Include this .cc file in a project.

// foo.cc
// Fixes the new handler "bug".

#include <new>

void __my_new_handler (void) {
  throw bad_alloc();
}

class __dummy_class {
  __dummy_class (void) { set_new_handler(__may_new_handler); }
};

__dummy_class __dummy_object; // This will construct at startup, and the
                                                            // constructor will
set the new handler.


In another module, such as the one with main, #include this:

// foo.h

extern __dummy_class __dummy_object;  // Force linker to link the foo.o.

--
   .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
-()  <  circles, and bark is not smooth, nor does lightning travel in a
   `*'  straight line."    -------------------------------------------------
        -- B. Mandelbrot  |http://www3.sympatico.ca/bob.beland/indexn2f.html
_____________________ ____|________     Paul Derbyshire     pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|

David Vrabel wrote in message <35599b32 DOT 1408551 AT 192 DOT 168 DOT 1 DOT 250>...
>
>David.
>
>David Vrabel  d DOT vrabel AT n-shropshire DOT ac DOT uk
>A poor student (aren't they all) at:
>North Shropshire College
>Oswestry, Shropshire, UK

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019