diff options
author | Kenneth Heafield <github@kheafield.com> | 2021-04-01 01:28:07 +0300 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2021-04-01 01:28:07 +0300 |
commit | d3657687c9b84d2ea2ea39b2fac7b89597bde848 (patch) | |
tree | db98acbd4b212de166b0670e5dc60db5426af1ca | |
parent | 1a176394bb0c2d243c42fe574e063924a92aa120 (diff) |
Move sematics for AlignedVector
-rw-r--r-- | intgemm/aligned.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/intgemm/aligned.h b/intgemm/aligned.h index 7500a8c..6fda369 100644 --- a/intgemm/aligned.h +++ b/intgemm/aligned.h @@ -5,24 +5,39 @@ #include <malloc.h> #endif -// 64-byte aligned simple vector. +// Aligned simple vector. namespace intgemm { template <class T> class AlignedVector { public: - explicit AlignedVector(std::size_t size) + AlignedVector() : mem_(nullptr), size_(0) {} + + explicit AlignedVector(std::size_t size, std::size_t alignment = 64 /* CPU cares about this */) : size_(size) { #ifdef _MSC_VER - mem_ = static_cast<T*>(_aligned_malloc(size * sizeof(T), 64)); + mem_ = static_cast<T*>(_aligned_malloc(size * sizeof(T), alignment)); if (!mem_) throw std::bad_alloc(); #else - if (posix_memalign(reinterpret_cast<void **>(&mem_), 64, size * sizeof(T))) { + if (posix_memalign(reinterpret_cast<void **>(&mem_), alignment, size * sizeof(T))) { throw std::bad_alloc(); } #endif } + AlignedVector(AlignedVector &&from) : mem_(from.mem_), size_(from.size_) { + from.mem_ = nullptr; + from.size_ = 0; + } + + AlignedVector &operator=(AlignedVector &&from) { + mem_ = from.mem_; + size_ = from.size_; + from.mem_ = nullptr; + from.size_ = 0; + return *this; + } + AlignedVector(const AlignedVector&) = delete; AlignedVector& operator=(const AlignedVector&) = delete; |