7 #include <boost/memory/alignment.hpp> 8 #include <boost/memory/null_allocator.hpp> 9 #include <boost/memory/memory_block.hpp> 12 namespace boost {
namespace memory {
20 template <
typename bitmapped_block_type>
21 class bitmapped_block_helper final
24 bitmapped_block_helper(bitmapped_block_type& instance) noexcept;
26 auto& get_allocator() noexcept;
27 auto& get_bitmap() noexcept;
31 bitmapped_block_type& instance_;
34 template <typename bitmap_type>
38 bitmap_helper(bitmap_type& instance) noexcept;
40 std::uint8_t& get_flag(std::size_t index);
41 constexpr std::size_t flags_count() const noexcept;
44 bitmap_type& instance_;
64 std::
size_t alignment=NO_ALIGNMENT>
68 static_assert(is_power_of_2(capacity),
"capacity has to be a power of 2!");
69 static_assert(alignment > 0,
"alignment has to be equal or greater than 1!");
74 template <std::
size_t size>
78 void set(std::size_t index);
79 void reset(std::size_t index);
81 bool is_set(std::size_t index);
83 bool claim(std::size_t& index);
87 friend bitmap_helper<bitmap_type>;
89 static constexpr std::uint8_t all_mask = 0b11111111;
90 static constexpr std::uint8_t flag_mask(std::uint8_t index)
92 std::uint8_t flag_masks[8] = {
103 return flag_masks[index];
106 std::uint8_t flags_[size] {};
109 using allocator_type = allocator;
110 using bitmap_type =
bitmap<(capacity % 8 == 0 ? capacity / 8 : capacity / 8 + 1)>;
112 static const std::size_t min_size = min;
113 static const std::size_t max_size = max;
114 static const std::size_t aligned_max_size = align_size<alignment>(max);
115 static const std::size_t blocks_count = capacity;
124 friend bitmapped_block_helper<this_bitmapped_block>;
126 allocator allocator_;
134 #include "bitmapped_block.ipp"
A continous memory block divided into equal number of sub-block with a bitmap indicating availability...
Represents an allocated memory block.