2 * @brief Memory allocation functions.
10 /** MEMALLOC declares the allocators for a class to allocate
11 * memory in the non-snapshotting heap. */
13 void * operator new(size_t size) { \
14 return MYMALLOC(size);\
16 void operator delete(void *p, size_t size) { \
19 void * operator new[](size_t size) { \
20 return MYMALLOC(size);\
22 void operator delete[](void *p, size_t size) {\
26 /** SNAPSHOTALLOC declares the allocators for a class to allocate
27 * memory in the snapshotting heap. */
30 void *MYMALLOC(size_t size);
31 void MYFREE(void *ptr);
33 void system_free( void * ptr );
34 void *system_malloc( size_t size );
36 /** @brief Provides a non-snapshotting allocator for use in STL classes.
38 * The code was adapted from a code example from the book The C++
39 * Standard Library - A Tutorial and Reference by Nicolai M. Josuttis,
40 * Addison-Wesley, 1999 © Copyright Nicolai M. Josuttis 1999
41 * Permission to copy, use, modify, sell and distribute this software
42 * is granted provided this copyright notice appears in all copies.
43 * This software is provided "as is" without express or implied
44 * warranty, and with no claim as to its suitability for any purpose.
52 typedef const T* const_pointer;
54 typedef const T& const_reference;
55 typedef size_t size_type;
56 typedef size_t difference_type;
58 // rebind allocator to type U
61 typedef MyAlloc<U> other;
64 // return address of values
65 pointer address (reference value) const {
68 const_pointer address (const_reference value) const {
72 /* constructors and destructor
73 * - nothing to do because the allocator has no state
77 MyAlloc(const MyAlloc&) throw() {
80 MyAlloc (const MyAlloc<U>&) throw() {
85 // return maximum number of elements that can be allocated
86 size_type max_size () const throw() {
87 return std::numeric_limits<size_t>::max() / sizeof(T);
90 // allocate but don't initialize num elements of type T
91 pointer allocate (size_type num, const void* = 0) {
92 pointer p = ( pointer )MYMALLOC( num * sizeof( T ) );
96 // initialize elements of allocated storage p with value value
97 void construct (pointer p, const T& value) {
98 // initialize memory with placement new
99 new((void*)p)T(value);
102 // destroy elements of initialized storage p
103 void destroy (pointer p) {
104 // destroy objects by calling their destructor
108 // deallocate storage p of deleted elements
109 void deallocate (pointer p, size_type num) {
114 /** Return that all specializations of this allocator are interchangeable. */
115 template <class T1, class T2>
116 bool operator== (const MyAlloc<T1>&,
117 const MyAlloc<T2>&) throw() {
121 /** Return that all specializations of this allocator are interchangeable. */
122 template <class T1, class T2>
123 bool operator!= (const MyAlloc<T1>&,
124 const MyAlloc<T2>&) throw() {
131 typedef void * mspace;
132 extern void* mspace_malloc(mspace msp, size_t bytes);
133 extern void mspace_free(mspace msp, void* mem);
134 extern void* mspace_realloc(mspace msp, void* mem, size_t newsize);
135 extern void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
136 extern mspace create_mspace_with_base(void* base, size_t capacity, int locked);
137 extern mspace create_mspace(size_t capacity, int locked);
138 extern mspace mySpace;
139 extern void * basemySpace;
141 }; /* end of extern "C" */
144 #endif /* _MY_MEMORY_H */