Protium
Math and Design Features
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
FixedAllocator.h
Go to the documentation of this file.
1 #ifndef Protium_FixedAllocator_h_
2 #define Protium_FixedAllocator_h_
3 
5 
6 #include <vector>
7 
8 namespace Protium{
9 
10  namespace Allocation{
11 
14 
15  private:
16 
20  void DoDeallocate( void * p );
21 
27  bool MakeNewChunk( void );
28 
41  Chunk * VicinityFind( void * p ) const;
42 
47 
49  typedef std::vector< Chunk > Chunks;
51  typedef Chunks::iterator ChunkIter;
53  typedef Chunks::const_iterator ChunkCIter;
54 
56  static unsigned char MinObjectsPerChunk_;
57 
59  static unsigned char MaxObjectsPerChunk_;
60 
62  std::size_t blockSize_;
64  unsigned char numBlocks_;
65 
74 
75  public:
78 
81 
83  void Initialize( std::size_t blockSize, std::size_t pageSize );
84 
88  void * Allocate( void );
89 
95  bool Deallocate( void * p, Chunk * hint );
96 
98  inline std::size_t BlockSize() const { return blockSize_; }
99 
104  bool TrimEmptyChunk( void );
105 
111  bool TrimChunkList( void );
112 
116  std::size_t CountEmptyChunks( void ) const;
117 
124  bool IsCorrupt( void ) const;
125 
130  const Chunk * HasBlock( void * p ) const;
131  inline Chunk * HasBlock( void * p )
132  {
133  return const_cast< Chunk * >(
134  const_cast< const FixedAllocator * >( this )->HasBlock( p ) );
135  }
136 
137  };//Class FixedAllocator
138 
139  }//Namespace Allocation
140 
141 }//Namespace Protium
142 
143 #endif //File Guardian
FixedAllocator()
Create a FixedAllocator which manages blocks of 'blockSize' size.
Chunk * allocChunk_
Pointer to Chunk used for last or next allocation.
Pool of allocation chunks.
Chunks::iterator ChunkIter
Iterator through container of Chunks.
static unsigned char MaxObjectsPerChunk_
Most # of objects managed by a Chunk - never exceeds UCHAR_MAX.
Chunk * VicinityFind(void *p) const
FixedAllocator & operator=(const FixedAllocator &)
Not implemented.
std::size_t blockSize_
Number of bytes in a single block within a Chunk.
Chunk * emptyChunk_
Pointer to the only empty Chunk if there is one, else NULL.
Chunk * deallocChunk_
Pointer to Chunk used for last or next deallocation.
void Initialize(std::size_t blockSize, std::size_t pageSize)
Initializes a FixedAllocator by calculating # of blocks per Chunk.
bool Deallocate(void *p, Chunk *hint)
Chunks chunks_
Container of Chunks.
const Chunk * HasBlock(void *p) const
Represents a fixed number of blocks.
Definition: Chunk.h:16
unsigned char numBlocks_
Number of blocks managed by each Chunk.
static unsigned char MinObjectsPerChunk_
Fewest # of objects managed by a Chunk.
std::size_t CountEmptyChunks(void) const
std::size_t BlockSize() const
Returns block size with which the FixedAllocator was initialized.
std::vector< Chunk > Chunks
Type of container used to hold Chunks.
~FixedAllocator()
Destroy the FixedAllocator and release all its Chunks.
Chunks::const_iterator ChunkCIter
Iterator through const container of Chunks.