libstdc++
|
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, 2009, 2010, 2011 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional 00020 // permissions described in the GCC Runtime Library Exception, version 00021 // 3.1, as published by the Free Software Foundation. 00022 00023 // You should have received a copy of the GNU General Public License and 00024 // a copy of the GCC Runtime Library Exception along with this program; 00025 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00026 // <http://www.gnu.org/licenses/>. 00027 00028 /** @file new 00029 * This is a Standard C++ Library header. 00030 * 00031 * The header @c new defines several functions to manage dynamic memory and 00032 * handling memory allocation errors; see 00033 * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more. 00034 */ 00035 00036 #ifndef _NEW 00037 #define _NEW 00038 00039 #pragma GCC system_header 00040 00041 #include <bits/c++config.h> 00042 #include <exception> 00043 00044 #pragma GCC visibility push(default) 00045 00046 extern "C++" { 00047 00048 namespace std 00049 { 00050 /** 00051 * @brief Exception possibly thrown by @c new. 00052 * @ingroup exceptions 00053 * 00054 * @c bad_alloc (or classes derived from it) is used to report allocation 00055 * errors from the throwing forms of @c new. */ 00056 class bad_alloc : public exception 00057 { 00058 public: 00059 bad_alloc() throw() { } 00060 00061 // This declaration is not useless: 00062 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00063 virtual ~bad_alloc() throw(); 00064 00065 // See comment in eh_exception.cc. 00066 virtual const char* what() const throw(); 00067 }; 00068 00069 struct nothrow_t { }; 00070 00071 extern const nothrow_t nothrow; 00072 00073 /** If you write your own error handler to be called by @c new, it must 00074 * be of this type. */ 00075 typedef void (*new_handler)(); 00076 00077 /// Takes a replacement handler as the argument, returns the 00078 /// previous handler. 00079 new_handler set_new_handler(new_handler) throw(); 00080 } // namespace std 00081 00082 //@{ 00083 /** These are replaceable signatures: 00084 * - normal single new and delete (no arguments, throw @c bad_alloc on error) 00085 * - normal array new and delete (same) 00086 * - @c nothrow single new and delete (take a @c nothrow argument, return 00087 * @c NULL on error) 00088 * - @c nothrow array new and delete (same) 00089 * 00090 * Placement new and delete signatures (take a memory address argument, 00091 * does nothing) may not be replaced by a user's program. 00092 */ 00093 void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) 00094 __attribute__((__externally_visible__)); 00095 void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) 00096 __attribute__((__externally_visible__)); 00097 void operator delete(void*) _GLIBCXX_USE_NOEXCEPT 00098 __attribute__((__externally_visible__)); 00099 void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT 00100 __attribute__((__externally_visible__)); 00101 void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT 00102 __attribute__((__externally_visible__)); 00103 void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT 00104 __attribute__((__externally_visible__)); 00105 void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT 00106 __attribute__((__externally_visible__)); 00107 void operator delete[](void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT 00108 __attribute__((__externally_visible__)); 00109 00110 // Default placement versions of operator new. 00111 inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT 00112 { return __p; } 00113 inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT 00114 { return __p; } 00115 00116 // Default placement versions of operator delete. 00117 inline void operator delete (void*, void*) _GLIBCXX_USE_NOEXCEPT { } 00118 inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { } 00119 //@} 00120 } // extern "C++" 00121 00122 #pragma GCC visibility pop 00123 00124 #endif