Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
rw_new.h
Go to the documentation of this file.
1
29#ifndef RW_NEW_H_INCLUDED
30#define RW_NEW_H_INCLUDED
31
32
33// this file must be #included in at most one translation unit in a program
34// (replacement operators new and delete must be defined in at most one
35// translation unit in order not to violate the ODR)
36
37#include <new> // for bad_alloc
38
39#include <rw_testdefs.h> // for test config macros
40
41
43{
44 // cumulative number of all calls to the ordinary operator new
45 // and the array form of the operator, respectively, regardless
46 // of whether they exited successfully or by throwing an exception
47 _RWSTD_SIZE_T new_calls_ [2];
48
49 // cumulative number of calls to the ordinary operator delete
50 // and the array form of the operator, respectively, regardless
51 // of whether they exited successfully or by throwing an exception
52 _RWSTD_SIZE_T delete_calls_ [2];
53
54 // cumulative number of calls to the ordinary operator delete
55 // and the array form of the operator, respectively, with the
56 // argument of 0
57 _RWSTD_SIZE_T delete_0_calls_ [2];
58
59 // number of blocks currently allocated by the ordinary operator new,
60 // and the array form of the operator, respectively
61 _RWSTD_SIZE_T blocks_ [2];
62
63 // number of bytes currently allocated by the ordinary operator new,
64 // and the array form of the operator, respectively
65 _RWSTD_SIZE_T bytes_ [2];
66
67 // the maximum number of blocks allocated so far by the ordinary
68 // operator new, and the array form of the operator, respectively
69 _RWSTD_SIZE_T max_blocks_ [2];
70
71 // the maximum total amount of storage allocated so far by the ordinary
72 // operator new, and the array form of the operator, respectively
73 _RWSTD_SIZE_T max_bytes_ [2];
74
75 // the size of the largest block allocated so far by the ordinary
76 // operator new, and the array form of the operator, respectively
77 _RWSTD_SIZE_T max_block_size_ [2];
78
79 // pointer to a value which, when equal to new_calls_ [i],
80 // the ordinary operator new (for i == 0) or the array form
81 // of the operator (for i == 1), respectively, will throw
82 // a std::bad_alloc exception
83 _RWSTD_SIZE_T* throw_at_calls_ [2];
84
85 // pointer to a value which, when less than or equal to blocks_ [i]
86 // during the next call to the ordinary operator new (for i == 0) or
87 // the array form of the operator (for i == 1), respectively, will
88 // throw a std::bad_alloc exception
89 _RWSTD_SIZE_T* throw_at_blocks_ [2];
90
91 // pointer to a value which, when less than or equal to bytes_ [i]
92 // during the next call to the ordinary operator new (for i == 0) or
93 // the array form of the operator (for i == 1), respectively, will
94 // throw a std::bad_alloc exception
95 _RWSTD_SIZE_T* throw_at_bytes_ [2];
96
97 // pointer to a value which, when equal to the next block's sequence
98 // number operator new will break or abort
99 _RWSTD_SIZE_T* break_at_seqno_;
100};
101
102
103// returns a pointer to the global rwt_free_store object
104// with a non-zero argument sets the global pointer to the rwt_free_store
105// object to the value of the argument
108
109// computes the difference between two states of the free store
110// returns 0 when no difference exists, otherwise a pointer to
111// a rwt_free_store structure describing the differences
112// when both arguments are 0, returns the difference between
113// the last checkpoint and the current states of the free store,
114// and establishes a new checkpoint
115// when the first argument is 0, returns the difference between
116// the last checkpoint and the current states of the free store
117// when the second argument is 0, returns the difference between
118// the state specified by the first argument and the current state
119// of the free store
122
123// returns the number of blocks allocated and not freed since
124// the checkpoint specified by the second argument
125// when the second argument is 0, returns the number of blocks
126// allocated and not freed since the last established checkpoint
127// and establishes a new checkpoint
128_TEST_EXPORT _RWSTD_SIZE_T
129rwt_check_leaks (_RWSTD_SIZE_T*, const rwt_free_store*);
130
131
132// define replacement operator new and delete to keep track
133// of allocated memory and allow for exceptions to be thrown
134
135_TEST_EXPORT void* operator_new (_RWSTD_SIZE_T, bool);
136_TEST_EXPORT void operator_delete (void*, bool);
137
138# ifndef _RWSTD_BAD_ALLOC
139 // #define if not #defined by <new> (SunPro #includes its
140 // own <new> regardless of the preprocessor search path)
141# define _RWSTD_BAD_ALLOC _STD::bad_alloc
142# endif // _RWSTD_BAD_ALLOC
143
144
146{
147 MyNewInit ();
148 ~MyNewInit ();
149
150private:
151
152 // not defined
153 MyNewInit (const MyNewInit&);
154 void operator= (const MyNewInit&);
155};
156
157// keeps track of dynamic intiatlization
158static MyNewInit mynew_init_tracker;
159
160
161# ifndef _RWSTD_TEST_SRC
162# ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
163
164// prevent defining the replacement operator
165// when compiling in the test suite framework
166
167void* operator new (_RWSTD_SIZE_T n) _THROWS ((_RWSTD_BAD_ALLOC))
168{
169 return operator_new (n, false);
170}
171
172void operator delete (void *ptr) _THROWS (())
173{
174 operator_delete (ptr, false);
175}
176
177
178# if !defined (_RWSTD_NO_OPERATOR_NEW_ARRAY) \
179 || defined (_RWSTD_NO_EXT_OPERATOR_NEW)
180
181// replaceable only if we don't provide a definition in <new>
182void* operator new[] (_RWSTD_SIZE_T n) _THROWS ((_RWSTD_BAD_ALLOC))
183{
184 return operator_new (n, true);
185}
186
187# endif // !_RWSTD_NO_OPERATOR_NEW_ARRAY || _RWSTD_NO_EXT_OPERATOR_NEW
188
189# if !defined (_RWSTD_NO_OPERATOR_DELETE_ARRAY) \
190 || defined (_RWSTD_NO_EXT_OPERATOR_NEW)
191
192// replaceable only if we don't provide a definition in <new>
193void operator delete[] (void *ptr) _THROWS (())
194{
195 operator_delete (ptr, true);
196}
197
198
199# endif // !_NO_OPERATOR_DELETE_ARRAY || _NO_EXT_OPERATOR_NEW
200# endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
201# endif // !_RWSTD_TEST_SRC
202#endif // RW_NEW_H_INCLUDED
#define ptr
Definition 17.names.cpp:525
#define n
Definition 17.names.cpp:130
void(* operator_delete)(void *, void *)
void *(* operator_new)(size_t, void *)
#define _THROWS()
_TEST_EXPORT rwt_free_store * rwt_checkpoint(const rwt_free_store *, const rwt_free_store *)
Definition new.cpp:620
#define _RWSTD_BAD_ALLOC
Definition rw_new.h:141
_TEST_EXPORT _RWSTD_SIZE_T rwt_check_leaks(_RWSTD_SIZE_T *, const rwt_free_store *)
Definition new.cpp:684
_TEST_EXPORT rwt_free_store * rwt_get_free_store(rwt_free_store *)
Definition new.cpp:597
#define _TEST_EXPORT
Definition rw_testdefs.h:55
_RWSTD_SIZE_T delete_calls_[2]
Definition rw_new.h:52
_RWSTD_SIZE_T * throw_at_bytes_[2]
Definition rw_new.h:95
_RWSTD_SIZE_T max_blocks_[2]
Definition rw_new.h:69
_RWSTD_SIZE_T max_bytes_[2]
Definition rw_new.h:73
_RWSTD_SIZE_T bytes_[2]
Definition rw_new.h:65
_RWSTD_SIZE_T delete_0_calls_[2]
Definition rw_new.h:57
_RWSTD_SIZE_T * throw_at_calls_[2]
Definition rw_new.h:83
_RWSTD_SIZE_T max_block_size_[2]
Definition rw_new.h:77
_RWSTD_SIZE_T blocks_[2]
Definition rw_new.h:61
_RWSTD_SIZE_T * break_at_seqno_
Definition rw_new.h:99
_RWSTD_SIZE_T new_calls_[2]
Definition rw_new.h:47
_RWSTD_SIZE_T * throw_at_blocks_[2]
Definition rw_new.h:89