diff --git a/Makefile.am b/Makefile.am
index 7c618d3e326a45c8f6719691f58bde9a5a1c4c26..bad0185690207b20c536ceace77718261a0f6833 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,3 +1,7 @@
 SUBDIRS = src
 
-bin_PROGRAMS = 
\ No newline at end of file
+bin_PROGRAMS =
+
+test:
+	cd src && make test
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 70ae67deb7e389b7b7a3fd0e6bb1ec71ada2d9f4..0fd3dd7d9e5fd7597f2024a0d542ae940ad28ac9 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,4 +27,8 @@ Memleak_check.hpp ptr_info.hpp \
 util/se_util.hpp
 
 .cu.o :
-	$(NVCC) $(NVCCFLAGS) -I. $(INCLUDES_PATH) -o $@ -c $<
+	$(NVCC) $(NVCCFLAGS) -std=c++11  -I. $(INCLUDES_PATH) -o $@ -c $<
+
+test: mem
+	source $(HOME)/openfpm_vars && cd .. && ./src/mem
+
diff --git a/src/Memleak_check.hpp b/src/Memleak_check.hpp
index 7b8b8f0a6e7563a1a077967c838a9c95f929323e..dcdf9d8b0c818c5eb16873ad41cf027ebce3648f 100644
--- a/src/Memleak_check.hpp
+++ b/src/Memleak_check.hpp
@@ -28,6 +28,7 @@ typedef unsigned char * byte_ptr;
 
 #include "util/se_util.hpp"
 #include "ptr_info.hpp"
+#include <string>
 
 #define MEM_ERROR 1300lu
 
diff --git a/src/memory/CudaMemory.cu b/src/memory/CudaMemory.cu
index 86104305e4ede12f9d852476201118000034db72..05b217d326775bc9afd05964ed2ac70786d7195c 100644
--- a/src/memory/CudaMemory.cu
+++ b/src/memory/CudaMemory.cu
@@ -5,6 +5,25 @@
 #include "cuda_macro.h"
 #include <cstring>
 
+#define CUDA_EVENT 0x1201
+
+/*! \brief Move the memory into device
+ *
+ * \return true if the memory is correctly flushed
+ *
+ */
+bool CudaMemory::flush()
+{
+	if (hm != NULL && dm != NULL)
+	{
+		//! copy from host to device memory
+
+		CUDA_SAFE_CALL(cudaMemcpy(dm,hm,sz,cudaMemcpyHostToDevice));		
+	}
+	
+	return true;
+}
+
 /*! \brief Allocate a chunk of memory
  *
  * Allocate a chunk of memory
@@ -20,6 +39,9 @@ bool CudaMemory::allocate(size_t sz)
 
 	this->sz = sz;
 
+	// after allocation we canno ensure that hm is sync
+	is_hm_sync = false;
+
 	return true;
 }
 
@@ -47,6 +69,8 @@ void CudaMemory::destroy()
 #endif
 		hm = NULL;
 	}
+	
+	sz = 0;
 }
 
 /*! \brief Allocate the host buffer
@@ -111,7 +135,7 @@ bool CudaMemory::copyDeviceToDevice(const CudaMemory & m)
 	}
 
 	//! Copy the memory
-	CUDA_SAFE_CALL(cudaMemcpy(m.dm,dm,m.sz,cudaMemcpyDeviceToDevice));
+	CUDA_SAFE_CALL(cudaMemcpy(dm,m.dm,m.sz,cudaMemcpyDeviceToDevice));
 
 	return true;
 }
diff --git a/src/memory/CudaMemory.cuh b/src/memory/CudaMemory.cuh
index 2bebb5df73f577bfad9ef97a9b586afffd72456c..ef144fc60d4795e0159a7c9f1e33864688f52609 100644
--- a/src/memory/CudaMemory.cuh
+++ b/src/memory/CudaMemory.cuh
@@ -62,6 +62,8 @@ class CudaMemory : public memory
 	
 public:
 	
+	//! flush the memory
+	virtual bool flush();
 	//! allocate memory
 	virtual bool allocate(size_t sz);
 	//! destroy memory
@@ -109,6 +111,43 @@ public:
 		return false;
 	}
 	
+	// Copy the Heap memory
+	CudaMemory & operator=(const CudaMemory & mem)
+	{
+		copy(mem);
+		return *this;
+	}
+
+	// Copy the Cuda memory
+	CudaMemory(const CudaMemory & mem)
+	:CudaMemory()
+	{
+		allocate(mem.size());
+		copy(mem);
+	}
+
+	CudaMemory(CudaMemory && mem) noexcept
+	{
+
+		bool t_is_hm_sync = is_hm_sync;
+		size_t t_sz = sz;
+		void * t_dm = dm;
+		void * t_hm = hm;
+		long int t_ref_cnt = ref_cnt;
+
+		is_hm_sync = mem.is_hm_sync;
+		sz = mem.sz;
+		dm = mem.dm;
+		hm = mem.hm;
+
+		// reset mem
+		mem.is_hm_sync = t_is_hm_sync;
+		mem.sz = t_sz;
+		mem.dm = t_dm;
+		mem.hm = t_hm;
+		mem.ref_cnt = t_ref_cnt;
+	}
+	
 	//! Constructor
 	CudaMemory():is_hm_sync(true),sz(0),dm(0),hm(0),ref_cnt(0) {};
 	
diff --git a/src/memory/ExtPreAlloc.hpp b/src/memory/ExtPreAlloc.hpp
index 166c8ce1c6ecf3134a73e4e0e5b23f5602090bb7..2a6c26d5e8573aa525c9c33476761f42bc8d9bd0 100644
--- a/src/memory/ExtPreAlloc.hpp
+++ b/src/memory/ExtPreAlloc.hpp
@@ -88,6 +88,9 @@ public:
 		return ref_cnt;
 	}
 
+	//! flush the memory
+	virtual bool flush() {return mem->flush();};
+
 	/*! \brief Allocate a chunk of memory
 	 *
 	 * Allocate a chunk of memory
diff --git a/src/memory/HeapMemory.hpp b/src/memory/HeapMemory.hpp
index 01ce5f68dfcb78550b8b1da37926ecd9e7a9c0d8..c50298a4b560276eecbd27df1b2710239eb3f782 100644
--- a/src/memory/HeapMemory.hpp
+++ b/src/memory/HeapMemory.hpp
@@ -62,6 +62,8 @@ class HeapMemory : public memory
 
 public:
 
+	//! flush the memory
+	virtual bool flush() {return true;};
 	//! allocate memory
 	virtual bool allocate(size_t sz);
 	//! destroy memory
@@ -119,14 +121,13 @@ public:
 
 	HeapMemory(HeapMemory && mem) noexcept
 	{
-		//! swap
+		//! move
 		alignement = mem.alignement;
 		sz = mem.sz;
 		dm = mem.dm;
 		dmOrig = mem.dmOrig;
 		ref_cnt = mem.ref_cnt;
 
-		// reset mem
 		mem.alignement = MEM_ALIGNMENT;
 		mem.sz = 0;
 		mem.dm = NULL;
diff --git a/src/memory/HeapMemory_unit_tests.hpp b/src/memory/HeapMemory_unit_tests.hpp
index f1fc1bc299567f71449537839f4794923d47e810..a629898765171bc552b0067cf66b53c5a134369c 100644
--- a/src/memory/HeapMemory_unit_tests.hpp
+++ b/src/memory/HeapMemory_unit_tests.hpp
@@ -40,6 +40,8 @@ template<typename T> void test()
 	for (size_t i = 0 ; i < mem.size() ; i++)
 		ptr[i] = i;
 
+	mem.flush();
+
 	//! [Allocate some memory and fill with data]
 
 	//! [Resize the memory]
@@ -98,6 +100,8 @@ template<typename T> void test()
 	for (size_t i = 0 ; i < src.size() ; i++)
 		ptr[i] = i;
 
+	src.flush();
+
 	T dst = src;
 
 	unsigned char * ptr2 = (unsigned char *)dst.getPointer();
diff --git a/src/memory/PreAllocHeapMemory.hpp b/src/memory/PreAllocHeapMemory.hpp
index f08c02296f46426cd39c99a2959aa8e208711e49..c640f2f1890f4a7066a2d9be8e810b3caed59004 100644
--- a/src/memory/PreAllocHeapMemory.hpp
+++ b/src/memory/PreAllocHeapMemory.hpp
@@ -85,6 +85,9 @@ public:
 		return ref_cnt;
 	}
 
+	//! flush the memory
+	virtual bool flush() {return true;};
+
 	/*! \brief Allocate a chunk of memory
 	 *
 	 * Allocate a chunk of memory
diff --git a/src/memory/PtrMemory.hpp b/src/memory/PtrMemory.hpp
index 78f115803b04098150232ca3c4fc2277a31e8f55..76c998ed709513af8de305d36708b9feed09bc8d 100644
--- a/src/memory/PtrMemory.hpp
+++ b/src/memory/PtrMemory.hpp
@@ -61,6 +61,8 @@ class PtrMemory : public memory
 
 public:
 
+	//! flush the memory
+	virtual bool flush() {return true;};
 	//! allocate memory
 	virtual bool allocate(size_t sz);
 	//! destroy memory
diff --git a/src/memory/memory.hpp b/src/memory/memory.hpp
index 385c02edc68f5444565e779220031fefcc56e8ef..fe2bb99f88d1359ae18ea8b2d0d30ae0c84aceb1 100644
--- a/src/memory/memory.hpp
+++ b/src/memory/memory.hpp
@@ -23,6 +23,12 @@ class memory
 {
 	public:
 
+	/*! \brief Flush the memory into the device
+	 *
+	 *
+	 */
+	virtual bool flush() = 0;
+
 	/*! \brief allocate on device a buffer of
 	 *
 	 * Allocate on the device a buffer of memory
@@ -112,7 +118,6 @@ class memory
 	 */
 	virtual bool isInitialized() = 0;
 
-
 };
 
 #endif