home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / newop2.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  633b  |  28 lines

  1. // newop2 operator new(size_t, const nothrow_t&) for Microsoft C++
  2. #include <cstdlib>
  3. #include <new>
  4.  
  5. _C_LIB_DECL
  6. int _callnewh(size_t size);
  7. _END_C_LIB_DECL
  8.  
  9. void *operator new(size_t size, const std::nothrow_t&) _THROW0()
  10.     {    // try to allocate size bytes
  11.     void *p;
  12.     while ((p = malloc(size)) == 0)
  13.         {    // buy more memory or return null pointer
  14.         _TRY_BEGIN
  15.             if (_callnewh(size) == 0)
  16.                 break;
  17.         _CATCH(std::bad_alloc)
  18.             return (0);
  19.         _CATCH_END
  20.         }
  21.     return (p);
  22.     }
  23.  
  24. /*
  25.  * Copyright (c) 1995 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  26.  * Consult your license regarding permissions and restrictions.
  27.  */
  28.