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 *MYCALLOC(size_t count, size_t size);
32 void MYFREE(void *ptr);
34 void system_free( void * ptr );
35 void *system_malloc( size_t size );
37 /** @brief Provides a non-snapshotting allocator for use in STL classes.
39 * The code was adapted from a code example from the book The C++
40 * Standard Library - A Tutorial and Reference by Nicolai M. Josuttis,
41 * Addison-Wesley, 1999 © Copyright Nicolai M. Josuttis 1999
42 * Permission to copy, use, modify, sell and distribute this software
43 * is granted provided this copyright notice appears in all copies.
44 * This software is provided "as is" without express or implied
45 * warranty, and with no claim as to its suitability for any purpose.
53 typedef const T* const_pointer;
55 typedef const T& const_reference;
56 typedef size_t size_type;
57 typedef size_t difference_type;
59 // rebind allocator to type U
62 typedef MyAlloc<U> other;
65 // return address of values
66 pointer address (reference value) const {
69 const_pointer address (const_reference value) const {
73 /* constructors and destructor
74 * - nothing to do because the allocator has no state
78 MyAlloc(const MyAlloc&) throw() {
81 MyAlloc (const MyAlloc<U>&) throw() {
86 // return maximum number of elements that can be allocated
87 size_type max_size () const throw() {
88 return std::numeric_limits<size_t>::max() / sizeof(T);
91 // allocate but don't initialize num elements of type T
92 pointer allocate (size_type num, const void* = 0) {
93 pointer p = ( pointer )MYMALLOC( num * sizeof( T ) );
97 // initialize elements of allocated storage p with value value
98 void construct (pointer p, const T& value) {
99 // initialize memory with placement new
100 new((void*)p)T(value);
103 // destroy elements of initialized storage p
104 void destroy (pointer p) {
105 // destroy objects by calling their destructor
109 // deallocate storage p of deleted elements
110 void deallocate (pointer p, size_type num) {
115 /** Return that all specializations of this allocator are interchangeable. */
116 template <class T1, class T2>
117 bool operator== (const MyAlloc<T1>&,
118 const MyAlloc<T2>&) throw() {
122 /** Return that all specializations of this allocator are interchangeable. */
123 template <class T1, class T2>
124 bool operator!= (const MyAlloc<T1>&,
125 const MyAlloc<T2>&) throw() {
132 typedef void * mspace;
133 extern void* mspace_malloc(mspace msp, size_t bytes);
134 extern void mspace_free(mspace msp, void* mem);
135 extern void* mspace_realloc(mspace msp, void* mem, size_t newsize);
136 extern void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
137 extern mspace create_mspace_with_base(void* base, size_t capacity, int locked);
138 extern mspace create_mspace(size_t capacity, int locked);
139 extern mspace mySpace;
140 extern void * basemySpace;
142 }; /* end of extern "C" */
145 #endif /* _MY_MEMORY_H */