Код: Выделить всё
auto it = chunks_.begin();
for (;; ++it) {
if (it == chunks_.end()) {
chunks_.emplace_back();
alloc_chunk_ = &chunks_.back();
break;
}
if (!it->is_filled()) {
alloc_chunk_ = &*it;
break;
}
}
< /code>
до этого: < /p>
auto it = std::ranges::find_if(
chunks_, [](const auto &chunk) { return !chunk.is_filled(); });
if (it == chunks_.end()) {
chunks_.emplace_back();
alloc_chunk_ = &chunks_.back();
} else {
alloc_chunk_ = &*it;
}
Код: Выделить всё
chunks_Это Chunk s:
Код: Выделить всё
struct Chunk {
// ... other details ...
[[nodiscard]] bool is_filled() const { return !blocks_available_; }
unsigned char data_[num_blocks_];
unsigned char first_available_ = 0;
unsigned char blocks_available_ = num_blocks_;
};
Подробнее здесь: https://stackoverflow.com/questions/730 ... is-so-fast
Мобильная версия