Lines Matching refs:Block
50 /// As an example, the diagram below represents two contiguous `Block`s. The
54 /// Block 1:
62 /// Block 2:
75 /// Block 1 (used):
83 /// Block 2:
94 class Block {
102 Block(const Block &other) = delete;
103 Block &operator=(const Block &other) = delete;
108 static optional<Block *> init(ByteSpan region);
110 /// @returns A pointer to a `Block`, given a pointer to the start of the
117 LIBC_INLINE static Block *from_usable_space(void *usable_space) {
119 return reinterpret_cast<Block *>(bytes - sizeof(Block));
121 LIBC_INLINE static const Block *from_usable_space(const void *usable_space) {
123 return reinterpret_cast<const Block *>(bytes - sizeof(Block));
131 return inner_size - sizeof(prev_) + sizeof(Block);
159 return outer_size - sizeof(Block);
166 auto *s = reinterpret_cast<cpp::byte *>(this) + sizeof(Block);
172 const auto *s = reinterpret_cast<const cpp::byte *>(this) + sizeof(Block);
190 optional<Block *> split(size_t new_inner_size,
198 LIBC_INLINE Block *next() const {
201 return reinterpret_cast<Block *>(reinterpret_cast<uintptr_t>(this) +
206 LIBC_INLINE Block *prev_free() const {
209 return reinterpret_cast<Block *>(reinterpret_cast<uintptr_t>(this) - prev_);
230 LIBC_INLINE Block(size_t outer_size, bool is_last) : next_(outer_size) {
233 // to Block.
235 outer_size % (is_last ? alignof(Block) : alignof(max_align_t)) == 0 &&
262 if (add_overflow(size, sizeof(Block), size))
278 // This block's usable space is aligned to max_align_t >= Block. With zero
279 // padding, the next block's usable space is sizeof(Block) past it, which is
280 // a point aligned to Block. Thus the max padding needed is alignment -
281 // alignof(Block).
282 if (add_overflow(size, alignment - alignof(Block), size))
292 Block *block;
300 Block *prev;
305 Block *next;
310 static BlockInfo allocate(Block *block, size_t alignment, size_t size);
315 return align_up(ptr + sizeof(Block), usable_space_alignment) -
316 sizeof(Block);
320 return align_down(ptr, usable_space_alignment) - sizeof(Block);
326 LIBC_INLINE static Block *as_block(ByteSpan bytes) {
327 LIBC_ASSERT(reinterpret_cast<uintptr_t>(bytes.data()) % alignof(Block) ==
330 return ::new (bytes.data()) Block(bytes.size(), /*is_last=*/false);
334 LIBC_ASSERT(reinterpret_cast<uintptr_t>(start) % alignof(Block) == 0 &&
336 ::new (start) Block(sizeof(Block), /*is_last=*/true);
364 static_assert(alignof(Block) >= 4,
368 optional<Block *> Block::init(ByteSpan region) {
385 if (block_start + sizeof(Block) > last_start)
389 Block *block =
397 Block::BlockInfo Block::allocate(Block *block, size_t alignment, size_t size) {
404 Block *original = info.block;
406 optional<Block *> maybe_aligned_block = original->split(0, alignment);
410 if (Block *prev = original->prev_free()) {
418 Block *aligned_block = *maybe_aligned_block;
425 if (optional<Block *> next = info.block->split(size))
432 optional<Block *> Block::split(size_t new_inner_size,
453 outer_size() - new_outer_size < sizeof(Block))
460 Block *new_block = as_block(new_region);
470 bool Block::merge_next() {