contur2
Loading...
Searching...
No Matches
contur::BlockAllocator Class Referencefinal

Allocates and frees fixed-size disk blocks. More...

#include <block_allocator.h>

Public Member Functions

 BlockAllocator (std::size_t totalBlocks)
 Creates a block allocator over a fixed number of blocks.
 ~BlockAllocator ()
 BlockAllocator (const BlockAllocator &)=delete
BlockAllocatoroperator= (const BlockAllocator &)=delete
 BlockAllocator (BlockAllocator &&) noexcept
BlockAllocatoroperator= (BlockAllocator &&) noexcept
Result< std::size_t > allocate ()
 Allocates one free block.
Result< void > free (std::size_t blockIndex)
 Frees a previously allocated block.
bool isFree (std::size_t blockIndex) const noexcept
 Returns whether block is free.
std::size_t totalBlocks () const noexcept
 Total number of blocks managed by allocator.
std::size_t freeBlocks () const noexcept
 Number of currently free blocks.
void reset ()
 Resets allocator state, marking every block as free.

Private Attributes

std::unique_ptr< Impl > impl_

Detailed Description

Allocates and frees fixed-size disk blocks.

Tracks free/used state for each block and provides O(n) first-fit allocation suitable for educational simulation.

Definition at line 16 of file block_allocator.h.

Constructor & Destructor Documentation

◆ BlockAllocator() [1/3]

contur::BlockAllocator::BlockAllocator ( std::size_t totalBlocks)
explicit

Creates a block allocator over a fixed number of blocks.

Parameters
totalBlocksTotal number of allocatable blocks.

◆ ~BlockAllocator()

contur::BlockAllocator::~BlockAllocator ( )

◆ BlockAllocator() [2/3]

contur::BlockAllocator::BlockAllocator ( const BlockAllocator & )
delete

◆ BlockAllocator() [3/3]

contur::BlockAllocator::BlockAllocator ( BlockAllocator && )
noexcept

Member Function Documentation

◆ allocate()

Result< std::size_t > contur::BlockAllocator::allocate ( )
nodiscard

Allocates one free block.

Returns
Block index on success; OutOfMemory if no free blocks remain.

◆ free()

Result< void > contur::BlockAllocator::free ( std::size_t blockIndex)
nodiscard

Frees a previously allocated block.

Parameters
blockIndexIndex of block to free.
Returns
Ok on success; InvalidAddress or InvalidState on misuse.

◆ freeBlocks()

std::size_t contur::BlockAllocator::freeBlocks ( ) const
nodiscardnoexcept

Number of currently free blocks.

Returns
Free block count.

◆ isFree()

bool contur::BlockAllocator::isFree ( std::size_t blockIndex) const
nodiscardnoexcept

Returns whether block is free.

Parameters
blockIndexBlock index to query.
Returns
True when free; false for used or out-of-range indices.

◆ operator=() [1/2]

BlockAllocator & contur::BlockAllocator::operator= ( BlockAllocator && )
noexcept

◆ operator=() [2/2]

BlockAllocator & contur::BlockAllocator::operator= ( const BlockAllocator & )
delete

◆ reset()

void contur::BlockAllocator::reset ( )

Resets allocator state, marking every block as free.

◆ totalBlocks()

std::size_t contur::BlockAllocator::totalBlocks ( ) const
nodiscardnoexcept

Total number of blocks managed by allocator.

Returns
Total block capacity.

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> contur::BlockAllocator::impl_
private

Definition at line 56 of file block_allocator.h.


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