Protium
Math and Design Features
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Protium::Allocation::Chunk Class Reference

Represents a fixed number of blocks. More...

#include <Chunk.h>

Private Member Functions

void * Allocate (std::size_t blocks)
 Allocates out a number of additional blocks. More...
 
void Deallocate (void *p, std::size_t blocks)
 DeAllocates a number of blocks starting at pointer. More...
 
bool HasAvailable (unsigned char numBlocks) const
 Checks to see if this number of blocks is available in this chunk. More...
 
bool HasBlock (void *p, std::size_t chunkLength) const
 Checks if this block belongs to this chunk. More...
 
bool Init (std::size_t size, unsigned char n)
 
bool IsBlockAvailable (void *p, unsigned char numBlocks, std::size_t blockSize) const
 Checks the block starting at p and for p+numBlocks*blockSize checks to see if they're used. More...
 
bool IsCorrupt (unsigned char numBlocks, std::size_t blockSize, bool checkIndexes) const
 
bool IsFilled (void) const
 Checks to see if this is filled. More...
 
void Release ()
 Deallocates all blocks in chunck. More...
 
void Reset (std::size_t blockSize, unsigned char blocks)
 Each time a chunk is reused, it needs to be reset. More...
 

Private Attributes

unsigned char * fData
 
unsigned char fFirstAvailable
 First Available block. More...
 
unsigned char fNAvail
 Number of available blocks. More...
 

Friends

class FixedAllocator
 Since all members are private, only FixedAllocator can access them. More...
 

Detailed Description

Represents a fixed number of blocks.

Definition at line 16 of file Chunk.h.

Member Function Documentation

void * Protium::Allocation::Chunk::Allocate ( std::size_t  blocks)
private

Allocates out a number of additional blocks.

Definition at line 30 of file Chunk.cxx.

void Protium::Allocation::Chunk::Deallocate ( void *  p,
std::size_t  blocks 
)
private

DeAllocates a number of blocks starting at pointer.

Definition at line 43 of file Chunk.cxx.

bool Protium::Allocation::Chunk::HasAvailable ( unsigned char  numBlocks) const
inlineprivate

Checks to see if this number of blocks is available in this chunk.

Definition at line 59 of file Chunk.h.

bool Protium::Allocation::Chunk::HasBlock ( void *  p,
std::size_t  chunkLength 
) const
inlineprivate

Checks if this block belongs to this chunk.

Definition at line 54 of file Chunk.h.

bool Protium::Allocation::Chunk::Init ( std::size_t  size,
unsigned char  n 
)
private

Each time a new chunk is created, it must be initialized (or when reused in a pool)

Parameters
sizethe size per chunk
nthe number of blocks

Definition at line 6 of file Chunk.cxx.

bool Protium::Allocation::Chunk::IsBlockAvailable ( void *  p,
unsigned char  numBlocks,
std::size_t  blockSize 
) const
private

Checks the block starting at p and for p+numBlocks*blockSize checks to see if they're used.

Definition at line 160 of file Chunk.cxx.

bool Protium::Allocation::Chunk::IsCorrupt ( unsigned char  numBlocks,
std::size_t  blockSize,
bool  checkIndexes 
) const
private

Determines whether this chunk is corrupt The following conditions imply corruption:

  • Number of available blocks exceeds the number of blocks contained
  • The last block occurs before the first block (overwrite)
  • For each block:
    • If block is found outside outside of bounds
    • Block occurs twice

Definition at line 61 of file Chunk.cxx.

bool Protium::Allocation::Chunk::IsFilled ( void  ) const
inlineprivate

Checks to see if this is filled.

Definition at line 63 of file Chunk.h.

void Protium::Allocation::Chunk::Release ( )
private

Deallocates all blocks in chunck.

Definition at line 24 of file Chunk.cxx.

void Protium::Allocation::Chunk::Reset ( std::size_t  blockSize,
unsigned char  blocks 
)
private

Each time a chunk is reused, it needs to be reset.

Definition at line 15 of file Chunk.cxx.

Friends And Related Function Documentation

friend class FixedAllocator
friend

Since all members are private, only FixedAllocator can access them.

Definition at line 28 of file Chunk.h.

Member Data Documentation

unsigned char* Protium::Allocation::Chunk::fData
private

Data

Definition at line 19 of file Chunk.h.

unsigned char Protium::Allocation::Chunk::fFirstAvailable
private

First Available block.

Definition at line 22 of file Chunk.h.

unsigned char Protium::Allocation::Chunk::fNAvail
private

Number of available blocks.

Definition at line 25 of file Chunk.h.