7 void * operator new(size_t size) { \
8 return MYMALLOC(size);\
10 void operator delete(void *p, size_t size) { \
13 void * operator new[](size_t size) { \
14 return MYMALLOC(size);\
16 void operator delete[](void *p, size_t size) {\
20 /* Empty define; represents opposite of MEMALLOC */
23 void *MYMALLOC(size_t size);
24 void MYFREE(void *ptr);
27 The following code example is taken from the book
28 The C++ Standard Library - A Tutorial and Reference
29 by Nicolai M. Josuttis, Addison-Wesley, 1999
30 © Copyright Nicolai M. Josuttis 1999
31 Permission to copy, use, modify, sell and distribute this software
32 is granted provided this copyright notice appears in all copies.
33 This software is provided "as is" without express or implied
34 warranty, and with no claim as to its suitability for any purpose.
42 typedef const T* const_pointer;
44 typedef const T& const_reference;
45 typedef size_t size_type;
46 typedef size_t difference_type;
48 // rebind allocator to type U
51 typedef MyAlloc<U> other;
54 // return address of values
55 pointer address (reference value) const {
58 const_pointer address (const_reference value) const {
62 /* constructors and destructor
63 * - nothing to do because the allocator has no state
67 MyAlloc(const MyAlloc&) throw() {
70 MyAlloc (const MyAlloc<U>&) throw() {
75 // return maximum number of elements that can be allocated
76 size_type max_size () const throw() {
77 return std::numeric_limits<size_t>::max() / sizeof(T);
80 // allocate but don't initialize num elements of type T
81 pointer allocate (size_type num, const void* = 0) {
82 pointer p = ( pointer )MYMALLOC( num * sizeof( T ) );
86 // initialize elements of allocated storage p with value value
87 void construct (pointer p, const T& value) {
88 // initialize memory with placement new
89 new((void*)p)T(value);
92 // destroy elements of initialized storage p
93 void destroy (pointer p) {
94 // destroy objects by calling their destructor
98 // deallocate storage p of deleted elements
99 void deallocate (pointer p, size_type num) {
104 // return that all specializations of this allocator are interchangeable
105 template <class T1, class T2>
106 bool operator== (const MyAlloc<T1>&,
107 const MyAlloc<T2>&) throw() {
110 template <class T1, class T2>
111 bool operator!= (const MyAlloc<T1>&,
112 const MyAlloc<T2>&) throw() {
119 typedef void * mspace;
120 extern void* mspace_malloc(mspace msp, size_t bytes);
121 extern void mspace_free(mspace msp, void* mem);
122 extern mspace create_mspace_with_base(void* base, size_t capacity, int locked);
123 extern mspace create_mspace(size_t capacity, int locked);
124 extern mspace mySpace;
125 extern void * basemySpace;
127 }; /* end of extern "C" */
130 #endif /* _MY_MEMORY_H */