~ubuntu-branches/ubuntu/raring/muse/raring

« back to all changes in this revision

Viewing changes to .pc/gcc46.patch/muse/memory.h

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2011-08-12 11:16:41 UTC
  • mfrom: (1.1.9) (10.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20110812111641-sjz0e93fr0ozfv0b
Tags: 2.0~beta2-1
* New maintainer (see bug 637185#12), thanks Daniel!
* New upstream release (Closes: #627371):
  - New interface Qt4-based (Closes: #604584)
* Refresh packaging:
  - Move to DH7 and source format 3.0 (quilt).
  - Refresh patchset.
  - Fix a bunch lintian warnings.
  - debian/postinst:
    + Use set -e in the body rather than pass -e on the #! line to make it
      have actually effect if it is run by hand with "sh /path/to/script".
  - Update instructions on how-to increase RTC clock frequency.
    Thanks to Torquil Macdonald Sørensen for the report (Closes: #570833).
  - Bump Standards.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=========================================================
2
 
//  MusE
3
 
//  Linux Music Editor
4
 
//  $Id: memory.h,v 1.4.2.3 2009/12/15 22:08:50 spamatica Exp $
5
 
//
6
 
//  (C) Copyright 2003-2004 Werner Schweer (ws@seh.de)
7
 
//=========================================================
8
 
 
9
 
#ifndef __MEMORY_H__
10
 
#define __MEMORY_H__
11
 
 
12
 
#include <stdio.h>
13
 
#include <stdlib.h>
14
 
#include <map>
15
 
 
16
 
// most of the following code is based on examples
17
 
// from Bjarne Stroustrup: "Die C++ Programmiersprache"
18
 
 
19
 
//---------------------------------------------------------
20
 
//   Pool
21
 
//---------------------------------------------------------
22
 
 
23
 
class Pool {
24
 
      struct Verweis {
25
 
            Verweis* next;
26
 
            };
27
 
      struct Chunk {
28
 
            enum { size = 4 * 1024 };
29
 
            Chunk* next;
30
 
            char mem[size];
31
 
            };
32
 
      enum { dimension = 21 };
33
 
      Chunk* chunks[dimension];
34
 
      Verweis* head[dimension];
35
 
      Pool(Pool&);
36
 
      void operator=(Pool&);
37
 
      void grow(int idx);
38
 
 
39
 
   public:
40
 
      Pool();
41
 
      ~Pool();
42
 
      void* alloc(size_t n);
43
 
      void free(void* b, size_t n);
44
 
      };
45
 
 
46
 
//---------------------------------------------------------
47
 
//   alloc
48
 
//---------------------------------------------------------
49
 
 
50
 
inline void* Pool::alloc(size_t n)
51
 
      {
52
 
      if (n == 0)
53
 
            return 0;
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);
57
 
            exit(-1);
58
 
            }
59
 
      if (head[idx] == 0)
60
 
            grow(idx);
61
 
      Verweis* p = head[idx];
62
 
      head[idx] = p->next;
63
 
      return p;
64
 
      }
65
 
 
66
 
//---------------------------------------------------------
67
 
//   free
68
 
//---------------------------------------------------------
69
 
 
70
 
inline void Pool::free(void* b, size_t n)
71
 
      {
72
 
      if (b == 0 || n == 0)
73
 
            return;
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);
77
 
            exit(-1);
78
 
            }
79
 
      Verweis* p = static_cast<Verweis*>(b);
80
 
      p->next = head[idx];
81
 
      head[idx] = p;
82
 
      }
83
 
 
84
 
extern Pool audioRTmemoryPool;
85
 
extern Pool midiRTmemoryPool;
86
 
 
87
 
//---------------------------------------------------------
88
 
//   audioRTalloc
89
 
//---------------------------------------------------------
90
 
 
91
 
template <class T> class audioRTalloc
92
 
      {
93
 
   public:
94
 
      typedef T         value_type;
95
 
      typedef size_t    size_type;
96
 
      typedef ptrdiff_t difference_type;
97
 
 
98
 
      typedef T*        pointer;
99
 
      typedef const T*  const_pointer;
100
 
 
101
 
      typedef T&        reference;
102
 
      typedef const T&  const_reference;
103
 
 
104
 
      pointer address(reference x) const { return &x; }
105
 
      const_pointer address(const_reference x) const { return &x; }
106
 
 
107
 
      audioRTalloc();
108
 
      template <class U> audioRTalloc(const audioRTalloc<U>&) {}
109
 
      ~audioRTalloc() {}
110
 
 
111
 
      pointer allocate(size_type n, void * = 0) {
112
 
            return static_cast<T*>(audioRTmemoryPool.alloc(n * sizeof(T)));
113
 
            }
114
 
      void deallocate(pointer p, size_type n) {
115
 
            audioRTmemoryPool.free(p, n * sizeof(T));
116
 
            }
117
 
 
118
 
      audioRTalloc<T>&  operator=(const audioRTalloc&) { return *this; }
119
 
      void construct(pointer p, const T& val) {
120
 
            new ((T*) p) T(val);
121
 
            }
122
 
      void destroy(pointer p) {
123
 
            p->~T();
124
 
            }
125
 
      size_type max_size() const { return size_t(-1); }
126
 
 
127
 
      template <class U> struct rebind { typedef audioRTalloc<U> other; };
128
 
      template <class U> audioRTalloc& operator=(const audioRTalloc<U>&) { return *this; }
129
 
      };
130
 
 
131
 
template <class T> audioRTalloc<T>::audioRTalloc() {}
132
 
 
133
 
//---------------------------------------------------------
134
 
//   midiRTalloc
135
 
//---------------------------------------------------------
136
 
 
137
 
template <class T> class midiRTalloc
138
 
      {
139
 
   public:
140
 
      typedef T         value_type;
141
 
      typedef size_t    size_type;
142
 
      typedef ptrdiff_t difference_type;
143
 
 
144
 
      typedef T*        pointer;
145
 
      typedef const T*  const_pointer;
146
 
 
147
 
      typedef T&        reference;
148
 
      typedef const T&  const_reference;
149
 
 
150
 
      pointer address(reference x) const { return &x; }
151
 
      const_pointer address(const_reference x) const { return &x; }
152
 
 
153
 
      midiRTalloc();
154
 
      template <class U> midiRTalloc(const midiRTalloc<U>&) {}
155
 
      ~midiRTalloc() {}
156
 
 
157
 
      pointer allocate(size_type n, void * = 0) {
158
 
            return static_cast<T*>(midiRTmemoryPool.alloc(n * sizeof(T)));
159
 
            }
160
 
      void deallocate(pointer p, size_type n) {
161
 
            midiRTmemoryPool.free(p, n * sizeof(T));
162
 
            }
163
 
 
164
 
      midiRTalloc<T>&  operator=(const midiRTalloc&) { return *this; }
165
 
      void construct(pointer p, const T& val) {
166
 
            new ((T*) p) T(val);
167
 
            }
168
 
      void destroy(pointer p) {
169
 
            p->~T();
170
 
            }
171
 
      size_type max_size() const { return size_t(-1); }
172
 
 
173
 
      template <class U> struct rebind { typedef midiRTalloc<U> other; };
174
 
      template <class U> midiRTalloc& operator=(const midiRTalloc<U>&) { return *this; }
175
 
      };
176
 
 
177
 
template <class T> midiRTalloc<T>::midiRTalloc() {}
178
 
 
179
 
#endif
180