[libc-commits] [libc] [libc] Add aligned_alloc (PR #96586)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Jun 25 09:01:59 PDT 2024
================
@@ -357,6 +392,58 @@ void Block<OffsetType, kAlign>::free(Block *&block) {
merge_next(block);
}
+template <typename OffsetType, size_t kAlign>
+bool Block<OffsetType, kAlign>::can_allocate(size_t alignment,
+ size_t size) const {
+ if (usable_space_is_aligned(alignment) && inner_size() >= size)
+ return true; // Size and alignment constraints met.
+
+ // Either the alignment isn't met or we don't have enough size.
+ // If we don't meet alignment, we can always adjust such that we do meet the
+ // alignment. If we meet the alignment but just don't have enough size. This
+ // check will fail anyway.
+ size_t adjustment = extra_space_for_adjustment(alignment);
+ if (inner_size() >= size + adjustment)
+ return true;
+
+ return false;
----------------
nickdesaulniers wrote:
```suggestion
return inner_size() >= size + extra_space_for_adjustment(alignment);
```
https://github.com/llvm/llvm-project/pull/96586
More information about the libc-commits
mailing list