1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org>
2 
3 #ifndef ALLOCATOR_H
4 #define ALLOCATOR_H
5 
6 #include "list.h"
7 
8 
9 class Allocator
10 {
11 public:
12     Allocator( uint );
13     ~Allocator();
14 
15     void * allocate( uint size, uint pointers );
16 
17     void * block( uint );
18 
19     static uint rounded( uint size );
20 
21     static Allocator * allocator( uint size );
22 
23     static Garbage * free( List<Garbage> * = 0 );
24     static void addEternal( const void *, const char * );
25 
26     static void removeEternal( void * );
27     static void removeEternal( const void * );
28 
29     static void setReporting( bool );
30 
31     static uint allocated();
32     static uint inUse();
33 
34     static void * alloc( uint, uint = UINT_MAX );
35     static void dealloc( void * );
36 
37     uint chunkSize() const;
38 
39     static Allocator * owner( const void * );
40     void deallocate( void * );
41 
42     void setNumPointers( const void *, uint );
43 
44     static uint sizeOf( void * );
45 
46     static uint allocatedFromOS();
47 
48 private:
49     typedef unsigned long int ulong;
50 
51     uint base;
52     uint step;
53     uint taken;
54     uint capacity;
55     ulong * used;
56     ulong * marked;
57     void * buffer;
58     Allocator * next;
59 
60     friend void pointers( void * );
61     friend class AllocatorMapTable;
62 
63 private:
64     static void mark( void * );
65     static void mark();
66     void sweep();
67 };
68 
69 
70 #endif
71