From: Michal Sojka Date: Sun, 30 Sep 2018 21:41:42 +0000 (+0200) Subject: DynMem: Make num_elem const and public and add assertions to move operations X-Git-Url: http://rtime.felk.cvut.cz/gitweb/hercules2020/kcf.git/commitdiff_plain/47b9012c3a5423f5b70fcba31a837886631a9529 DynMem: Make num_elem const and public and add assertions to move operations This will become handy in future commits. --- diff --git a/src/dynmem.hpp b/src/dynmem.hpp index 7f30ba1..ad36f61 100644 --- a/src/dynmem.hpp +++ b/src/dynmem.hpp @@ -19,9 +19,10 @@ template class DynMem_ { #ifdef CUFFT T *ptr_d = nullptr; #endif - size_t num_elem; public: typedef T value_type; + const size_t num_elem; + DynMem_(size_t num_elem) : num_elem(num_elem) { #ifdef CUFFT @@ -31,7 +32,8 @@ template class DynMem_ { ptr_h = new T[num_elem]; #endif } - DynMem_(DynMem_&& other) { + DynMem_(DynMem_ &&other) : num_elem(other.num_elem) + { ptr_h = other.ptr_h; other.ptr_h = nullptr; #ifdef CUFFT @@ -52,10 +54,12 @@ template class DynMem_ { T *deviceMem() { return ptr_d; } #endif void operator=(DynMem_ &rhs) { + assert(num_elem == rhs.num_elem); memcpy(ptr_h, rhs.ptr_h, num_elem * sizeof(T)); } void operator=(DynMem_ &&rhs) { + assert(num_elem == rhs.num_elem); ptr_h = rhs.ptr_h; rhs.ptr_h = nullptr; #ifdef CUFFT