3 #include "SDL_version.h" 4 #if SDL_VERSION_ATLEAST(2, 0, 10) 6 #include "SDL_cpuinfo.h" 16 return SDL_SIMDGetAlignment();
23 return SDL_SIMDAlloc(len);
27 inline void free(
void* ptr)
29 return SDL_SIMDFree(ptr);
54 #ifndef CPP_SDL2_DISABLE_EXCEPTIONS 55 if (!mem)
throw std::bad_alloc();
57 return std::launder(reinterpret_cast<T*>(
new (mem) std::byte[size *
sizeof(T)]));
72 static_assert(!(std::is_array_v<T> && std::extent_v<T> == 0),
"destroy_at<T[]> is invalid");
74 if constexpr (std::is_array_v<T>)
85 constexpr
deleter() noexcept =
default;
87 template<
typename U,
typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
103 std::size_t count = 0;
108 explicit constexpr
deleter(std::size_t size) noexcept : count(size) {}
110 template<
typename U,
typename = std::enable_if_t<std::is_convertible_v<U (*)[], T (*)[]>>>
116 auto operator()(U* ptr) -> std::enable_if_t<std::is_convertible_v<U (*)[], T (*)[]>>
127 template<
typename T,
typename... Args>
135 template<
typename T,
typename... Args>
141 -> std::enable_if_t<std::is_array_v<T> && std::extent_v<T> == 0,
unique_ptr<T>>
143 using U = std::remove_extent_t<T>;
146 for (std::size_t i = 0; i < count; ++i)
new (
mem + i) U;
151 template<
typename T,
typename... Args>
152 auto make_shared(Args&&... args) -> std::enable_if<!std::is_array_v<T>, std::shared_ptr<T>>
155 auto*
mem =
new (a.
allocate(1)) T(std::forward<Args>(args)...);
161 #endif // SDL_VERSION_ATLEAST(2, 0, 10) auto make_unique(Args &&... args) -> std::enable_if_t<!std::is_array_v< T >, unique_ptr< T >>
Equivalent of std::make_unique<T> that returns a simd::unique_ptr.
void operator()(T *ptr) noexcept
friend constexpr bool operator==(allocator, allocator) noexcept
auto operator()(U *ptr) -> std::enable_if_t< std::is_convertible_v< U(*)[], T(*)[]>>
constexpr deleter(deleter< U >) noexcept
T * allocate(std::size_t size)
std::unique_ptr< T, simd::deleter< T > > unique_ptr
void * alloc(size_t len)
Allocate memory in a SIMD-friendly way.
void free(void *ptr)
Deallocate memory obtained from sdl::simd::alloc().
size_t get_alignment()
Report the alignment this system needs for SIMD allocations.
constexpr allocator() noexcept=default
constexpr deleter(deleter< U[]> const &other) noexcept
Allocator usable with standard containers.
void deallocate(T *ptr, [[maybe_unused]] std::size_t size) noexcept
void destroy_at(T *ptr)
recursive implementation of std::destroy_at, only available from C++20 onwards.
friend constexpr bool operator!=(allocator, allocator) noexcept
constexpr deleter(std::size_t size) noexcept
auto make_shared(Args &&... args) -> std::enable_if<!std::is_array_v< T >, std::shared_ptr< T >>
Equivalent of std::make_shared<T> that uses simd-friendly storage.
deleter usable with std::unique_ptr<T>.