1
//=========================================================
4
// $Id: memory.h,v 1.4.2.3 2009/12/15 22:08:50 spamatica Exp $
6
// (C) Copyright 2003-2004 Werner Schweer (ws@seh.de)
7
//=========================================================
16
// most of the following code is based on examples
17
// from Bjarne Stroustrup: "Die C++ Programmiersprache"
19
//---------------------------------------------------------
21
//---------------------------------------------------------
28
enum { size = 4 * 1024 };
32
enum { dimension = 21 };
33
Chunk* chunks[dimension];
34
Verweis* head[dimension];
36
void operator=(Pool&);
42
void* alloc(size_t n);
43
void free(void* b, size_t n);
46
//---------------------------------------------------------
48
//---------------------------------------------------------
50
inline void* Pool::alloc(size_t n)
54
int idx = ((n + sizeof(unsigned long) - 1) / sizeof(unsigned long)) - 1;
55
if (idx >= dimension) {
56
printf("panic: alloc %zd %d %d\n", n, idx, dimension);
61
Verweis* p = head[idx];
66
//---------------------------------------------------------
68
//---------------------------------------------------------
70
inline void Pool::free(void* b, size_t n)
74
int idx = ((n + sizeof(unsigned long) - 1) / sizeof(unsigned long)) - 1;
75
if (idx >= dimension) {
76
printf("panic: free %zd %d %d\n", n, idx, dimension);
79
Verweis* p = static_cast<Verweis*>(b);
84
extern Pool audioRTmemoryPool;
85
extern Pool midiRTmemoryPool;
87
//---------------------------------------------------------
89
//---------------------------------------------------------
91
template <class T> class audioRTalloc
95
typedef size_t size_type;
96
typedef ptrdiff_t difference_type;
99
typedef const T* const_pointer;
101
typedef T& reference;
102
typedef const T& const_reference;
104
pointer address(reference x) const { return &x; }
105
const_pointer address(const_reference x) const { return &x; }
108
template <class U> audioRTalloc(const audioRTalloc<U>&) {}
111
pointer allocate(size_type n, void * = 0) {
112
return static_cast<T*>(audioRTmemoryPool.alloc(n * sizeof(T)));
114
void deallocate(pointer p, size_type n) {
115
audioRTmemoryPool.free(p, n * sizeof(T));
118
audioRTalloc<T>& operator=(const audioRTalloc&) { return *this; }
119
void construct(pointer p, const T& val) {
122
void destroy(pointer p) {
125
size_type max_size() const { return size_t(-1); }
127
template <class U> struct rebind { typedef audioRTalloc<U> other; };
128
template <class U> audioRTalloc& operator=(const audioRTalloc<U>&) { return *this; }
131
template <class T> audioRTalloc<T>::audioRTalloc() {}
133
//---------------------------------------------------------
135
//---------------------------------------------------------
137
template <class T> class midiRTalloc
140
typedef T value_type;
141
typedef size_t size_type;
142
typedef ptrdiff_t difference_type;
145
typedef const T* const_pointer;
147
typedef T& reference;
148
typedef const T& const_reference;
150
pointer address(reference x) const { return &x; }
151
const_pointer address(const_reference x) const { return &x; }
154
template <class U> midiRTalloc(const midiRTalloc<U>&) {}
157
pointer allocate(size_type n, void * = 0) {
158
return static_cast<T*>(midiRTmemoryPool.alloc(n * sizeof(T)));
160
void deallocate(pointer p, size_type n) {
161
midiRTmemoryPool.free(p, n * sizeof(T));
164
midiRTalloc<T>& operator=(const midiRTalloc&) { return *this; }
165
void construct(pointer p, const T& val) {
168
void destroy(pointer p) {
171
size_type max_size() const { return size_t(-1); }
173
template <class U> struct rebind { typedef midiRTalloc<U> other; };
174
template <class U> midiRTalloc& operator=(const midiRTalloc<U>&) { return *this; }
177
template <class T> midiRTalloc<T>::midiRTalloc() {}