diff options
author | Kenneth Heafield <github@kheafield.com> | 2020-04-13 16:00:25 +0300 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2020-04-13 16:00:25 +0300 |
commit | fb96b0851cf420ac49c13b361a503afffe386ada (patch) | |
tree | e9d0fd017c9f60b5293d8c6a995e84fffe456f03 | |
parent | e1970fc7bcc8354aadd077844554c0462aa31c08 (diff) |
Juse use posix_memalign everywhere
-rw-r--r-- | aligned.h | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -1,5 +1,6 @@ #pragma once #include <cstdlib> +#include <new> #include <stdlib.h> // 64-byte aligned simple vector. @@ -10,11 +11,9 @@ template <class T> class AlignedVector { public: explicit AlignedVector(std::size_t size) : size_(size) { - #ifdef __APPLE__ - posix_memalign(reinterpret_cast<void **>(&mem_), 64, size * sizeof(T)); - #else - mem_ = reinterpret_cast<T*>(aligned_alloc(64, (size * sizeof(T) + 63) & ~63)); // pedantic requirements for memory size on aligned_alloc in case it's not just a call to posix_memalign - #endif + if (posix_memalign(reinterpret_cast<void **>(&mem_), 64, size * sizeof(T))) { + throw std::bad_alloc(); + } } AlignedVector(const AlignedVector&) = delete; |