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));
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
SequentialAllocator::allocate
unsigned char * allocate(unsigned int size)
Definition: allocator.cc:132
ChunkAllocator::printSize
void printSize() const
Definition: allocator.cc:34
SequentialAllocator::~SequentialAllocator
~SequentialAllocator()
Definition: allocator.cc:124
Allocator
Definition: allocator.h:12
ChunkAllocator::ChunkAllocator
ChunkAllocator(unsigned int _csize=(1<< 20))
Definition: allocator.cc:23
ChunkAllocator::wastedspace
unsigned long int wastedspace
Definition: allocator.h:39
ChunkAllocator::chunksize
const unsigned int chunksize
Definition: allocator.h:36
ChunkAllocator::index
unsigned int index
Definition: allocator.h:37
PackedChunkAllocator::memsize
unsigned long int memsize
Definition: allocator.h:55
ChunkAllocator::~ChunkAllocator
~ChunkAllocator()
Definition: allocator.cc:27
Allocator::printSize
virtual void printSize() const =0
PackedChunkAllocator::PackedChunkAllocator
PackedChunkAllocator(unsigned int _csize=(1<< 20))
Definition: allocator.cc:69
SequentialAllocator::SequentialAllocator
SequentialAllocator(unsigned char *base_ptr, unsigned int max_size)
Handle a preallocated memory up to max_size.
Definition: allocator.cc:120
PackedChunkAllocator::~PackedChunkAllocator
~PackedChunkAllocator()
Definition: allocator.cc:73
ChunkAllocator
Definition: allocator.h:27
SequentialAllocator::m_base_ptr
unsigned char * m_base_ptr
Definition: allocator.h:69
PackedChunkAllocator::allocate
unsigned char * allocate(unsigned int size)
Definition: allocator.cc:93
PackedChunkAllocator::index
std::vector< unsigned int > index
Definition: allocator.h:53
PackedChunkAllocator::chunksize
const unsigned int chunksize
Definition: allocator.h:54
SequentialAllocator::m_index
unsigned int m_index
Definition: allocator.h:70
ChunkAllocator::allocate
unsigned char * allocate(unsigned int size)
Definition: allocator.cc:40
SequentialAllocator
Definition: allocator.h:60
ChunkAllocator::mem
std::vector< unsigned char * > mem
Definition: allocator.h:35
SequentialAllocator::m_size
unsigned int m_size
Definition: allocator.h:70
Allocator::allocate
T * allocate(unsigned int nr=1)
Definition: allocator.h:17
ChunkAllocator::memsize
unsigned long int memsize
Definition: allocator.h:38
PackedChunkAllocator
Definition: allocator.h:44
Allocator::~Allocator
virtual ~Allocator()
Definition: allocator.h:14
SequentialAllocator::printSize
void printSize() const
Definition: allocator.cc:127
PackedChunkAllocator::mem
std::vector< unsigned char * > mem
Definition: allocator.h:52
PackedChunkAllocator::printSize
void printSize() const
Definition: allocator.cc:80


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 Wed Mar 2 2022 00:37:22