00001 // The -*- C++ -*- dynamic memory management header. 00002 00003 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 00004 // 2003, 2004, 2005, 2006, 2007 00005 // Free Software Foundation 00006 00007 // This file is part of GCC. 00008 // 00009 // GCC is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2, or (at your option) 00012 // any later version. 00013 // 00014 // GCC is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with GCC; see the file COPYING. If not, write to 00021 // the Free Software Foundation, 51 Franklin Street, Fifth Floor, 00022 // Boston, MA 02110-1301, USA. 00023 00024 // As a special exception, you may use this file as part of a free software 00025 // library without restriction. Specifically, if other files instantiate 00026 // templates or use macros or inline functions from this file, or you compile 00027 // this file and link it with other files to produce an executable, this 00028 // file does not by itself cause the resulting executable to be covered by 00029 // the GNU General Public License. This exception does not however 00030 // invalidate any other reasons why the executable file might be covered by 00031 // the GNU General Public License. 00032 00033 /** @file new 00034 * This is a Standard C++ Library header. 00035 * 00036 * The header @c new defines several functions to manage dynamic memory and 00037 * handling memory allocation errors; see 00038 * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more. 00039 */ 00040 00041 #ifndef _NEW 00042 #define _NEW 00043 00044 #include <cstddef> 00045 #include <exception> 00046 00047 #pragma GCC visibility push(default) 00048 00049 extern "C++" { 00050 00051 namespace std 00052 { 00053 /** 00054 * @brief Exception possibly thrown by @c new. 00055 * 00056 * @c bad_alloc (or classes derived from it) is used to report allocation 00057 * errors from the throwing forms of @c new. */ 00058 class bad_alloc : public exception 00059 { 00060 public: 00061 bad_alloc() throw() { } 00062 00063 // This declaration is not useless: 00064 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00065 virtual ~bad_alloc() throw(); 00066 00067 // See comment in eh_exception.cc. 00068 virtual const char* what() const throw(); 00069 }; 00070 00071 struct nothrow_t { }; 00072 00073 extern const nothrow_t nothrow; 00074 00075 /** If you write your own error handler to be called by @c new, it must 00076 * be of this type. */ 00077 typedef void (*new_handler)(); 00078 00079 /// Takes a replacement handler as the argument, returns the 00080 /// previous handler. 00081 new_handler set_new_handler(new_handler) throw(); 00082 } // namespace std 00083 00084 //@{ 00085 /** These are replaceable signatures: 00086 * - normal single new and delete (no arguments, throw @c bad_alloc on error) 00087 * - normal array new and delete (same) 00088 * - @c nothrow single new and delete (take a @c nothrow argument, return 00089 * @c NULL on error) 00090 * - @c nothrow array new and delete (same) 00091 * 00092 * Placement new and delete signatures (take a memory address argument, 00093 * does nothing) may not be replaced by a user's program. 00094 */ 00095 void* operator new(std::size_t) throw (std::bad_alloc); 00096 void* operator new[](std::size_t) throw (std::bad_alloc); 00097 void operator delete(void*) throw(); 00098 void operator delete[](void*) throw(); 00099 void* operator new(std::size_t, const std::nothrow_t&) throw(); 00100 void* operator new[](std::size_t, const std::nothrow_t&) throw(); 00101 void operator delete(void*, const std::nothrow_t&) throw(); 00102 void operator delete[](void*, const std::nothrow_t&) throw(); 00103 00104 // Default placement versions of operator new. 00105 inline void* operator new(std::size_t, void* __p) throw() { return __p; } 00106 inline void* operator new[](std::size_t, void* __p) throw() { return __p; } 00107 00108 // Default placement versions of operator delete. 00109 inline void operator delete (void*, void*) throw() { } 00110 inline void operator delete[](void*, void*) throw() { } 00111 //@} 00112 } // extern "C++" 00113 00114 #pragma GCC visibility pop 00115 00116 #endif