Whole document tree new_opnt.ccGo to the documentation of this file.00001 // Support routines for the -*- C++ -*- dynamic memory management. 00002 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation 00003 // 00004 // This file is part of GNU CC. 00005 // 00006 // GNU CC is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 // 00011 // GNU CC is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with GNU CC; see the file COPYING. If not, write to 00018 // the Free Software Foundation, 59 Temple Place - Suite 330, 00019 // Boston, MA 02111-1307, USA. 00020 // 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 #include "new" 00031 #include <exception_defines.h> 00032 00033 using std::new_handler; 00034 using std::bad_alloc; 00035 00036 extern "C" void *malloc (std::size_t); 00037 extern new_handler __new_handler; 00038 00039 void * 00040 operator new (std::size_t sz, const std::nothrow_t&) throw() 00041 { 00042 void *p; 00043 00044 /* malloc (0) is unpredictable; avoid it. */ 00045 if (sz == 0) 00046 sz = 1; 00047 p = (void *) malloc (sz); 00048 while (p == 0) 00049 { 00050 new_handler handler = __new_handler; 00051 if (! handler) 00052 return 0; 00053 try 00054 { 00055 handler (); 00056 } 00057 catch (bad_alloc &) 00058 { 00059 return 0; 00060 } 00061 00062 p = (void *) malloc (sz); 00063 } 00064 00065 return p; 00066 } Generated on Mon Apr 8 03:11:30 2002 for libstdc++-v3 Source by ![]() |