# Loki::FixedAllocator Class Reference
[Internals]

Collaboration diagram for Loki::FixedAllocator:
[legend]

List of all members.

## Public Member Functions

| FixedAllocator ()
| Create a FixedAllocator which manages blocks of 'blockSize' size.
| ~FixedAllocator ()
| Destroy the FixedAllocator and release all its Chunks.
void | Initialize (std::size_t blockSize, std::size_t pageSize)
| Initializes a FixedAllocator by calculating # of blocks per Chunk.
void * | Allocate (void)
bool | Deallocate (void *p, Chunk *hint)
std::size_t | BlockSize () const
| Returns block size with which the FixedAllocator was initialized.
bool | TrimEmptyChunk (void)
bool | TrimChunkList (void)
std::size_t | CountEmptyChunks (void) const
bool | IsCorrupt (void) const
const Chunk * | HasBlock (void *p) const

## Detailed Description

Offers services for allocating fixed-sized objects. It has a container of "containers" of fixed-size blocks. The outer container has all the Chunks. The inner container is a Chunk which owns some blocks.

Class Level Invariants
  - There is always either zero or one Chunk which is empty.
  - If this has no empty Chunk, then emptyChunk_ is NULL.
  - If this has an empty Chunk, then emptyChunk_ points to it.
  - If the Chunk container is empty, then deallocChunk_ and allocChunk_ are NULL.
  - If the Chunk container is not-empty, then deallocChunk_ and allocChunk_ are either NULL or point to Chunks within the container.
  - allocChunk_ will often point to the last Chunk in the container since it was likely allocated most recently, and therefore likely to have an available block.

## Member Function Documentation

void * Loki::FixedAllocator::Allocate | ( | void |  | ) |

Returns pointer to allocated memory block of fixed size - or NULL if it failed to allocate.

References Loki::Chunk::Allocate(), CountEmptyChunks(), Loki::Chunk::HasAvailable(), Loki::Chunk::IsCorrupt(), and Loki::Chunk::IsFilled().

Referenced by Loki::SmallObjAllocator::Allocate().

Here is the call graph for this function:

std::size_t Loki::FixedAllocator::CountEmptyChunks | ( | void |  | ) | const

Returns count of empty Chunks held by this allocator. Complexity is O(C) where C is the total number of Chunks - empty or used.

References Loki::Chunk::HasAvailable().

Referenced by Allocate(), Deallocate(), IsCorrupt(), and TrimEmptyChunk().

Here is the call graph for this function:

bool Loki::FixedAllocator::Deallocate | ( | void * | p,
|  | Chunk * | hint |
| ) |  |  |

Deallocate a memory block previously allocated with Allocate. If the block is not owned by this FixedAllocator, it returns false so that SmallObjAllocator can call the default deallocator. If the block was found, this returns true.

References CountEmptyChunks(), Loki::Chunk::HasBlock(), Loki::Chunk::IsBlockAvailable(), and Loki::Chunk::IsCorrupt().

Referenced by Loki::SmallObjAllocator::Deallocate().

Here is the call graph for this function:

const Chunk * Loki::FixedAllocator::HasBlock | ( | void * | p | ) | const

Returns true if the block at address p is within a Chunk owned by this FixedAllocator. Complexity is O(C) where C is the total number of Chunks - empty or used.

References Loki::Chunk::HasBlock().

Referenced by Loki::SmallObjAllocator::Deallocate().

Here is the call graph for this function:

bool Loki::FixedAllocator::IsCorrupt | ( | void |  | ) | const

Determines if FixedAllocator is corrupt. Checks data members to see if any have erroneous values, or violate class invariants. It also checks if any Chunk is corrupt. Complexity is O(C) where C is the number of Chunks. If any data is corrupt, this will return true in release mode, or assert in debug mode.

References CountEmptyChunks(), Loki::Chunk::HasAvailable(), and Loki::Chunk::IsCorrupt().

Here is the call graph for this function:

bool Loki::FixedAllocator::TrimChunkList | ( | void |  | ) |

Releases unused spots from ChunkList. This takes constant time with respect to # of Chunks, but actual time depends on underlying memory allocator.

Returns:
  False if no unused spots, true if some found and released.

bool Loki::FixedAllocator::TrimEmptyChunk | ( | void |  | ) |

Releases the memory used by the empty Chunk. This will take constant time under any situation.

Returns:
  True if empty chunk found and released, false if none empty.

References Loki::Chunk::blocksAvailable_, CountEmptyChunks(), Loki::Chunk::HasAvailable(), and Loki::Chunk::Release().

Referenced by ~FixedAllocator().

Here is the call graph for this function:

The documentation for this class was generated from the following file:

- SmallObj.cpp