1
extern void checkMemoryChain(void* _p);
1
//=========================================================
4
// $Id: memory.h,v 1.1.1.1 2003/10/29 10:05:18 wschweer Exp $
6
// (C) Copyright 2003 Werner Schweer (ws@seh.de)
7
//=========================================================
15
// most of the following code is based on examples
16
// from Bjarne Stroustrup: Die C++ Programmiersprache
18
//---------------------------------------------------------
20
//---------------------------------------------------------
27
enum { size = 4 * 1024 };
31
enum { dimension = 8 };
32
Chunk* chunks[dimension];
33
Verweis* head[dimension];
35
void operator=(Pool&);
41
void* alloc(size_t n);
42
void free(void* b, size_t n);
45
//---------------------------------------------------------
47
//---------------------------------------------------------
49
inline void* Pool::alloc(size_t n)
51
int idx = ((n + sizeof(int) - 1) / sizeof(int)) - 1;
52
if (idx >= dimension) {
53
printf("panic: alloc %d\n", n);
58
Verweis* p = head[idx];
63
//---------------------------------------------------------
65
//---------------------------------------------------------
67
inline void Pool::free(void* b, size_t n)
69
int idx = ((n + sizeof(int) - 1) / sizeof(int)) - 1;
70
if (idx >= dimension) {
71
printf("panic: alloc %d\n", n);
74
Verweis* p = static_cast<Verweis*>(b);
79
extern Pool midiRTmemoryPool;
81
//---------------------------------------------------------
83
//---------------------------------------------------------
85
template <class T> class RTalloc
89
typedef size_t size_type;
90
typedef ptrdiff_t difference_type;
93
typedef const T* const_pointer;
96
typedef const T& const_reference;
98
pointer address(reference x) const { return &x; }
99
const_pointer address(const_reference x) const { return &x; }
102
template <class U> RTalloc(const RTalloc<U>&) {}
105
pointer allocate(size_type n, void * = 0) {
106
return static_cast<T*>(midiRTmemoryPool.alloc(n * sizeof(T)));
108
void deallocate(pointer p, size_type n) {
109
midiRTmemoryPool.free(p, n * sizeof(T));
112
RTalloc<T>& operator=(const RTalloc&) { return *this; }
113
void construct(pointer p, const T& val) {
116
void destroy(pointer p) {
119
size_type max_size() const { return size_t(-1); }
121
template <class U> struct rebind { typedef RTalloc<U> other; };
122
template <class U> RTalloc& operator=(const RTalloc<U>&) { return *this; }
125
template <class T> RTalloc<T>::RTalloc() {}