1#ifndef VEG_ALLOC_HPP_TAWYRUICS
2#define VEG_ALLOC_HPP_TAWYRUICS
18#include <AvailabilityMacros.h>
19#include <malloc/malloc.h>
20#define malloc_usable_size malloc_size
31#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101500 && \
32 (defined(_LIBCPP_HAS_ALIGNED_ALLOC) || defined(_LIBCPP_HAS_C11_FEATURES)) && \
33 defined(PROXSUITE_WITH_CPP_17)
37 return std::aligned_alloc(alignment, size);
39#elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
43 if (alignment <
sizeof(
void*)) {
44 alignment =
sizeof(
void*);
47 if (::posix_memalign(&p, alignment, size) != 0) {
61template<std::
size_t A, std::
size_t B>
62struct min_size : std::integral_constant<std::size_t, (A < B) ? A : B>
75struct alignment_of : min_size<sizeof(T), sizeof(offset_value<T>) - sizeof(T)>
81is_alignment(std::size_t value)
83 return (value > 0) && ((value & (value - 1)) == 0);
88align(std::size_t alignment, std::size_t size, void*& ptr, std::size_t& space)
91 char* p =
reinterpret_cast<char*
>(
92 ~(alignment - 1) & (
reinterpret_cast<std::size_t
>(ptr) + alignment - 1));
93 assert((p -
static_cast<char*
>(ptr)) >= 0);
94 std::size_t n = std::size_t(p -
static_cast<char*
>(ptr));
95 if (size + n <=
space) {
116 std::size_t n = size + alignment - N;
117 void* p = std::malloc(
sizeof(
void*) + n);
119 void* r =
static_cast<char*
>(p) +
sizeof(
void*);
120 (void)
align(alignment, size, r, n);
121 *(
static_cast<void**
>(r) - 1) = p;
145 (VEG_CONCEPT(nothrow_copyable<T>) &&
146 VEG_CONCEPT(nothrow_copy_assignable<T>))
147 ? CopyAvailable::yes_nothrow
148 : (VEG_CONCEPT(copyable<T>) &&
149 VEG_CONCEPT(copy_assignable<T>))
150 ? CopyAvailable::yes_maythrow
156 VEG_CONCEPT(nothrow_destructible<T>)
157 ? DtorAvailable::yes_nothrow
158 : DtorAvailable::yes_maythrow>
167#elif defined(__APPLE__)
168#if defined(PROXSUITE_WITH_CPP_17) && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
169 return alignment::aligned_alloc(align, (size +
mask) & ~
mask);
174#if defined(PROXSUITE_WITH_CPP_17) && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
175 return std::aligned_alloc(align, (size +
mask) & ~
mask);
203 static constexpr usize max_base_align =
alignof(std::max_align_t);
209 (layout.align <= max_base_align) ? std::free(ptr)
216 void* ptr = (layout.align <= max_base_align)
217 ? std::malloc(layout.byte_size)
223 return { ptr, ::malloc_usable_size(ptr) };
225 return { ptr,
_msize(ptr) };
264 usize )
const noexcept ->
bool
297 template<
typename T,
typename Alloc>
303 mem::destroy_at(ptr);
340 if (
data !=
nullptr) {
#define HEDLEY_UNLIKELY(expr)
#define VEG_INLINE_VAR(Name, Obj)
void terminate() noexcept
void * aligned_alloc(std::size_t alignment, std::size_t size)
void * align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space)
constexpr bool is_alignment(std::size_t value)
VEG_INLINE void aligned_free(usize, void *ptr) noexcept
VEG_INLINE auto aligned_alloc(usize align, usize size) noexcept -> void *
decltype(sizeof(0)) usize
#define VEG_NOEXCEPT_IF(...)
VEG_NODISCARD VEG_INLINE constexpr auto get() const noexcept -> T const &
VEG_INLINE ~ManagedAlloc()
VEG_NODISCARD static VEG_INLINE auto shrink(RefMut< SystemAlloc > alloc, void *ptr, Layout layout, usize new_size, RelocFn reloc) noexcept -> mem::AllocBlock
VEG_NODISCARD static VEG_INLINE auto grow(RefMut< SystemAlloc > alloc, void *ptr, Layout layout, usize new_size, RelocFn reloc) noexcept -> mem::AllocBlock
static VEG_INLINE void dealloc(RefMut< SystemAlloc >, void *ptr, Layout layout) noexcept
VEG_NODISCARD static VEG_NO_INLINE auto realloc(RefMut< SystemAlloc >, void *ptr, Layout layout, usize new_size, usize copy_size, RelocFn reloc) noexcept -> mem::AllocBlock
VEG_NODISCARD VEG_INLINE auto try_grow_in_place(void *, Layout, usize) const noexcept -> bool
VEG_NODISCARD static VEG_INLINE auto alloc(RefMut< SystemAlloc >, Layout layout) noexcept -> mem::AllocBlock
VEG_TEMPLATE((typename T, typename Alloc), requires(VEG_CONCEPT(copyable< T >)), VEG_NODISCARD VEG_INLINE static auto clone,(, RefMut< DefaultCloner >),(rhs, Ref< T >),(, RefMut< Alloc >)) VEG_NOEXCEPT_IF(VEG_CONCEPT(nothrow_copyable< T >)) -> T
VEG_TEMPLATE((typename T, typename Alloc), requires(VEG_CONCEPT(copyable< T >)), VEG_INLINE static void clone_from,(, RefMut< DefaultCloner >),(lhs, RefMut< T >),(rhs, Ref< T >),(, RefMut< Alloc >))
static VEG_INLINE void destroy(RefMut< DefaultCloner >, T *ptr, RefMut< Alloc >)
constexpr friend auto operator==(SystemAlloc, SystemAlloc) noexcept -> bool