Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/intgemm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2020-08-11 01:36:24 +0300
committerKenneth Heafield <github@kheafield.com>2020-08-11 01:36:24 +0300
commit94b2f0b8601758539f73f6b40952ca82e900b7fb (patch)
treeb862e668893d76f44d0f0a15a9825f0d277e9c10
parent10fcb2a324d17cb883125cc19c7d76ec7f847096 (diff)
Windows aligned allocator
-rw-r--r--aligned.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/aligned.h b/aligned.h
index 6af3c31..ad3d318 100644
--- a/aligned.h
+++ b/aligned.h
@@ -2,6 +2,9 @@
#include <cstdlib>
#include <new>
#include <stdlib.h>
+#ifdef _MSC_VER
+#include <malloc.h>
+#endif
// 64-byte aligned simple vector.
@@ -11,15 +14,26 @@ template <class T> class AlignedVector {
public:
explicit AlignedVector(std::size_t size)
: size_(size) {
+#ifdef _MSC_VER
+ mem_ = _aligned_malloc(size * sizeof(T), 64);
+ if (!mem_) throw std::bad_alloc();
+#else
if (posix_memalign(reinterpret_cast<void **>(&mem_), 64, size * sizeof(T))) {
throw std::bad_alloc();
}
+#endif
}
AlignedVector(const AlignedVector&) = delete;
AlignedVector& operator=(const AlignedVector&) = delete;
- ~AlignedVector() { std::free(mem_); }
+ ~AlignedVector() {
+#ifdef _MSC_VER
+ _aligned_free(mem_);
+#else
+ std::free(mem_);
+#endif
+ }
std::size_t size() const { return size_; }