contur2
Loading...
Searching...
No Matches
block_allocator.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <memory>
7
8#include "contur/core/error.h"
9
10namespace contur {
11
16 class BlockAllocator final
17 {
18 public:
21 explicit BlockAllocator(std::size_t totalBlocks);
23
24 BlockAllocator(const BlockAllocator &) = delete;
27 BlockAllocator &operator=(BlockAllocator &&) noexcept;
28
31 [[nodiscard]] Result<std::size_t> allocate();
32
36 [[nodiscard]] Result<void> free(std::size_t blockIndex);
37
41 [[nodiscard]] bool isFree(std::size_t blockIndex) const noexcept;
42
45 [[nodiscard]] std::size_t totalBlocks() const noexcept;
46
49 [[nodiscard]] std::size_t freeBlocks() const noexcept;
50
52 void reset();
53
54 private:
55 struct Impl;
56 std::unique_ptr<Impl> impl_;
57 };
58
59} // namespace contur
std::unique_ptr< Impl > impl_
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.
BlockAllocator(std::size_t totalBlocks)
Creates a block allocator over a fixed number of blocks.
void reset()
Resets allocator state, marking every block as free.
Result< std::size_t > allocate()
Allocates one free block.
BlockAllocator(BlockAllocator &&) noexcept
std::size_t totalBlocks() const noexcept
Total number of blocks managed by allocator.
BlockAllocator(const BlockAllocator &)=delete
std::size_t freeBlocks() const noexcept
Number of currently free blocks.
BlockAllocator & operator=(const BlockAllocator &)=delete
A result type that holds either a success value of type T or an ErrorCode.
Definition error.h:104
Error codes and Result<T> type for fallible operations.
Definition block.h:15