~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to muse/memory.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-08-12 11:16:41 UTC
  • mto: (1.1.9) (10.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20110812111641-72iatqb9jomjejko
ImportĀ upstreamĀ versionĀ 2.0~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//=========================================================
2
2
//  MusE
3
3
//  Linux Music Editor
4
 
//  $Id: memory.h,v 1.4 2004/06/07 21:46:08 wschweer Exp $
 
4
//  $Id: memory.h,v 1.4.2.3 2009/12/15 22:08:50 spamatica Exp $
5
5
//
6
6
//  (C) Copyright 2003-2004 Werner Schweer (ws@seh.de)
7
7
//=========================================================
10
10
#define __MEMORY_H__
11
11
 
12
12
#include <stdio.h>
 
13
#include <stdlib.h>
 
14
#include <cstddef>
13
15
#include <map>
14
16
 
15
17
// most of the following code is based on examples
28
30
            Chunk* next;
29
31
            char mem[size];
30
32
            };
31
 
//      enum { dimension = 11 };
32
 
      enum { dimension = 21 };      // increased for 64 bit architectures
 
33
      enum { dimension = 21 };
33
34
      Chunk* chunks[dimension];
34
35
      Verweis* head[dimension];
35
36
      Pool(Pool&);
49
50
 
50
51
inline void* Pool::alloc(size_t n)
51
52
      {
52
 
      int idx = ((n + sizeof(int) - 1) / sizeof(int)) - 1;
 
53
      if (n == 0)
 
54
            return 0;
 
55
      int idx = ((n + sizeof(unsigned long) - 1) / sizeof(unsigned long)) - 1;
53
56
      if (idx >= dimension) {
54
 
            printf("panic: alloc %d\n", n);
 
57
            printf("panic: alloc %zd %d %d\n", n, idx, dimension);
55
58
            exit(-1);
56
59
            }
57
60
      if (head[idx] == 0)
67
70
 
68
71
inline void Pool::free(void* b, size_t n)
69
72
      {
70
 
      int idx = ((n + sizeof(int) - 1) / sizeof(int)) - 1;
 
73
      if (b == 0 || n == 0)
 
74
            return;
 
75
      int idx = ((n + sizeof(unsigned long) - 1) / sizeof(unsigned long)) - 1;
71
76
      if (idx >= dimension) {
72
 
            printf("panic: alloc %d\n", n);
 
77
            printf("panic: free %zd %d %d\n", n, idx, dimension);
73
78
            exit(-1);
74
79
            }
75
80
      Verweis* p = static_cast<Verweis*>(b);