allocator.h
Go to the documentation of this file.
1 
7 #ifndef ALLOCATOR_H
8 #define ALLOCATOR_H
9 
10 #include <vector>
11 
12 class Allocator {
13 public:
14  virtual ~Allocator() {}
15 
16  template<typename T>
17  T* allocate(unsigned int nr = 1) { return reinterpret_cast<T*>(allocate(nr*sizeof(T))); }
18 
19  virtual void printSize() const = 0;
20 
21 protected:
22  virtual unsigned char* allocate(unsigned int size) = 0;
23 };
24 
25 
26 
27 class ChunkAllocator : public Allocator {
28 public:
29  ChunkAllocator(unsigned int _csize = (1 << 20));
30  ~ChunkAllocator();
31  void printSize() const;
32 protected:
33  unsigned char* allocate(unsigned int size);
34 private:
35  std::vector<unsigned char *> mem;
36  const unsigned int chunksize;
37  unsigned int index;
38  unsigned long int memsize;
39  unsigned long int wastedspace;
40 };
41 
42 
43 
45 public:
46  PackedChunkAllocator(unsigned int _csize = (1<<20));
48  void printSize() const;
49 protected:
50  unsigned char* allocate(unsigned int size);
51 private:
52  std::vector<unsigned char *> mem;
53  std::vector<unsigned int > index;
54  const unsigned int chunksize;
55  unsigned long int memsize;
56 };
57 
58 
59 
61 public:
63  SequentialAllocator(unsigned char* base_ptr, unsigned int max_size);
65  void printSize() const;
66 protected:
67  unsigned char* allocate(unsigned int size);
68 private:
69  unsigned char* m_base_ptr;
70  unsigned int m_size, m_index;
71 };
72 
73 #endif
std::vector< unsigned char * > mem
Definition: allocator.h:35
const unsigned int chunksize
Definition: allocator.h:54
virtual void printSize() const =0
unsigned int index
Definition: allocator.h:37
virtual ~Allocator()
Definition: allocator.h:14
unsigned long int wastedspace
Definition: allocator.h:39
unsigned int m_size
Definition: allocator.h:70
unsigned long int memsize
Definition: allocator.h:55
T * allocate(unsigned int nr=1)
Definition: allocator.h:17
std::vector< unsigned char * > mem
Definition: allocator.h:52
const unsigned int chunksize
Definition: allocator.h:36
unsigned long int memsize
Definition: allocator.h:38
std::vector< unsigned int > index
Definition: allocator.h:53
unsigned char * m_base_ptr
Definition: allocator.h:69


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06