]>
Commit | Line | Data |
---|---|---|
6305f20a | 1 | // The -*- C++ -*- dynamic memory management header. |
0c952af3 | 2 | |
d66ae36a PC |
3 | // Copyright (C) 1994, 1996, 1997, 1998, 2000, 2001, 2002 |
4 | // Free Software Foundation | |
6305f20a | 5 | |
cbecceb9 | 6 | // This file is part of GCC. |
6305f20a | 7 | // |
cbecceb9 | 8 | // GCC is free software; you can redistribute it and/or modify |
6305f20a BK |
9 | // it under the terms of the GNU General Public License as published by |
10 | // the Free Software Foundation; either version 2, or (at your option) | |
11 | // any later version. | |
12 | // | |
cbecceb9 | 13 | // GCC is distributed in the hope that it will be useful, |
6305f20a BK |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | // | |
18 | // You should have received a copy of the GNU General Public License | |
cbecceb9 | 19 | // along with GCC; see the file COPYING. If not, write to |
6305f20a BK |
20 | // the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | // Boston, MA 02111-1307, USA. | |
22 | ||
23 | // As a special exception, you may use this file as part of a free software | |
24 | // library without restriction. Specifically, if other files instantiate | |
25 | // templates or use macros or inline functions from this file, or you compile | |
26 | // this file and link it with other files to produce an executable, this | |
27 | // file does not by itself cause the resulting executable to be covered by | |
28 | // the GNU General Public License. This exception does not however | |
29 | // invalidate any other reasons why the executable file might be covered by | |
30 | // the GNU General Public License. | |
31 | ||
669f7a03 | 32 | /** @file new |
ffe94f83 | 33 | * The header @c new defines several functions to manage dynamic memory and |
669f7a03 PE |
34 | * handling memory allocation errors; see |
35 | * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more. | |
36 | */ | |
37 | ||
6305f20a BK |
38 | #ifndef __NEW__ |
39 | #define __NEW__ | |
40 | ||
6305f20a | 41 | #include <cstddef> |
6305f20a BK |
42 | #include <exception> |
43 | ||
44 | extern "C++" { | |
45 | ||
0c952af3 BK |
46 | namespace std |
47 | { | |
aa2d5ba2 PE |
48 | /** |
49 | * @brief Exception possibly thrown by @c new. | |
50 | * | |
51 | * @c bad_alloc (or classes derived from it) is used to report allocation | |
669f7a03 | 52 | * errors from the throwing forms of @c new. */ |
0c952af3 BK |
53 | class bad_alloc : public exception |
54 | { | |
6305f20a | 55 | public: |
f68147f7 | 56 | bad_alloc() throw() { } |
e05cd3dd PC |
57 | // This declaration is not useless: |
58 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 | |
d66ae36a | 59 | virtual ~bad_alloc() throw(); |
6305f20a BK |
60 | }; |
61 | ||
0c952af3 | 62 | struct nothrow_t { }; |
6305f20a | 63 | extern const nothrow_t nothrow; |
669f7a03 PE |
64 | /** If you write your own error handler to be called by @c new, it must |
65 | * be of this type. */ | |
6305f20a | 66 | typedef void (*new_handler)(); |
669f7a03 | 67 | /// Takes a replacement handler as the argument, returns the previous handler. |
984812cd | 68 | new_handler set_new_handler(new_handler) throw(); |
6305f20a BK |
69 | } // namespace std |
70 | ||
669f7a03 PE |
71 | //@{ |
72 | /** These are replaceable signatures: | |
73 | * - normal single new and delete (no arguments, throw @c bad_alloc on error) | |
74 | * - normal array new and delete (same) | |
75 | * - @c nothrow single new and delete (take a @c nothrow argument, return | |
76 | * @c NULL on error) | |
77 | * - @c nothrow array new and delete (same) | |
78 | * | |
79 | * Placement new and delete signatures (take a memory address argument, | |
80 | * does nothing) may not be replaced by a user's program. | |
81 | */ | |
d3a193e3 BK |
82 | void* operator new(std::size_t) throw (std::bad_alloc); |
83 | void* operator new[](std::size_t) throw (std::bad_alloc); | |
84 | void operator delete(void*) throw(); | |
85 | void operator delete[](void*) throw(); | |
86 | void* operator new(std::size_t, const std::nothrow_t&) throw(); | |
87 | void* operator new[](std::size_t, const std::nothrow_t&) throw(); | |
88 | void operator delete(void*, const std::nothrow_t&) throw(); | |
89 | void operator delete[](void*, const std::nothrow_t&) throw(); | |
6305f20a | 90 | |
0c952af3 | 91 | // Default placement versions of operator new. |
d3a193e3 BK |
92 | inline void* operator new(std::size_t, void* __p) throw() { return __p; } |
93 | inline void* operator new[](std::size_t, void* __p) throw() { return __p; } | |
51937d2c BK |
94 | |
95 | // Default placement versions of operator delete. | |
43be7fe7 MM |
96 | inline void operator delete (void*, void*) throw() { } |
97 | inline void operator delete[](void*, void*) throw() { } | |
669f7a03 | 98 | //@} |
6305f20a BK |
99 | } // extern "C++" |
100 | ||
101 | #endif |