![]() |
Contur 2
Educational OS kernel simulator
|
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 () | |
| Destroys block allocator. | |
| BlockAllocator (const BlockAllocator &)=delete | |
| Copy construction is disabled. | |
| BlockAllocator & | operator= (const BlockAllocator &)=delete |
| Copy assignment is disabled. | |
| BlockAllocator (BlockAllocator &&) noexcept | |
| Move-constructs allocator state. | |
| BlockAllocator & | operator= (BlockAllocator &&) noexcept |
| Move-assigns allocator state. | |
| 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_ |
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.
|
explicit |
Creates a block allocator over a fixed number of blocks.
| totalBlocks | Total number of allocatable blocks. |
References totalBlocks().
Referenced by BlockAllocator(), BlockAllocator(), operator=(), and operator=().
| contur::BlockAllocator::~BlockAllocator | ( | ) |
Destroys block allocator.
|
delete |
Copy construction is disabled.
References BlockAllocator().
|
noexcept |
Move-constructs allocator state.
References BlockAllocator().
|
nodiscard |
Allocates one free block.
References allocate().
Referenced by allocate().
|
nodiscard |
|
nodiscardnoexcept |
Number of currently free blocks.
References freeBlocks().
Referenced by freeBlocks().
|
nodiscardnoexcept |
|
noexcept |
Move-assigns allocator state.
References BlockAllocator().
|
delete |
Copy assignment is disabled.
References BlockAllocator().
| void contur::BlockAllocator::reset | ( | ) |
|
nodiscardnoexcept |
Total number of blocks managed by allocator.
References totalBlocks().
Referenced by BlockAllocator(), and totalBlocks().
|
private |
Definition at line 64 of file block_allocator.h.