]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
DynMem: Make num_elem const and public and add assertions to move operations
authorMichal Sojka <michal.sojka@cvut.cz>
Sun, 30 Sep 2018 21:41:42 +0000 (23:41 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Sun, 30 Sep 2018 21:41:42 +0000 (23:41 +0200)
This will become handy in future commits.

src/dynmem.hpp

index 7f30ba1b13a22b413dd68521c56e786a0d96a594..ad36f61ef6e50959b6f8900a4e663f11e0d8d6b5 100644 (file)
@@ -19,9 +19,10 @@ template <typename T> 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 <typename T> 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 <typename T> 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