new

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

Generated on Wed Jun 9 11:18:41 2004 for libstdc++-v3 Source by doxygen 1.3.7