-
Notifications
You must be signed in to change notification settings - Fork 5
/
memory.h
80 lines (63 loc) · 1.76 KB
/
memory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
This is memory.h
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#ifndef MEMORY_H /* guard against multiple inclusions */
#define MEMORY_H
#include "globals.h"
#include "constants.h"
namespace memory {
using namespace coxeter;
using namespace constants;
/******** type declarations *************************************************/
union Align;
class Arena;
class FixArena;
}
/******** function declarations *********************************************/
void* operator new (size_t size, memory::Arena& a);
void* operator new[] (size_t size, memory::Arena& a);
namespace memory {
Arena& arena();
void pause();
/******** Type definitions **************************************************/
union Align {
Ulong d_ulong;
void *d_voidptr;
};
class FixArena {
public:
};
class Arena {
struct MemBlock {
MemBlock *next;
};
MemBlock* d_list[sizeof(Ulong)*CHAR_BIT];
Ulong d_used[sizeof(Ulong)*CHAR_BIT];
Ulong d_allocated[sizeof(Ulong)*CHAR_BIT];
unsigned d_bsBits;
unsigned d_count;
void newBlock(unsigned b);
public:
/* constructors and destructors */
void operator delete(void* ptr)
{arena().free(ptr,sizeof(Arena));}
Arena(Ulong bsBits);
~Arena();
/* modifiers */
void *alloc(size_t n);
void *realloc(void *ptr, size_t old_size, size_t new_size);
void free(void *ptr, size_t n);
/* accessors */
Ulong allocSize(Ulong n, Ulong m) const;
Ulong byteSize(Ulong n, Ulong m) const;
void print(FILE* file) const;
};
}
/******** Inline implementations *****************************************/
inline void* operator new(size_t size, memory::Arena& a)
{return a.alloc(size);}
inline void* operator new[](size_t size, memory::Arena& a)
{return a.alloc(size);}
#endif