diff --git a/src/shogun/lib/memory.h b/src/shogun/lib/memory.h index b83fefc43cf..73eda8b4fcd 100644 --- a/src/shogun/lib/memory.h +++ b/src/shogun/lib/memory.h @@ -17,6 +17,7 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS #include +#include /* wrappers for malloc, free, realloc, calloc */ @@ -95,6 +96,13 @@ template void sg_generic_free(T* ptr) { sg_free(ptr); } + +template +SG_FORCED_INLINE void* memcpy(InputIt dest, OutputIt src, size_t count) +{ + return std::memcpy(static_cast(dest), static_cast(src), count); +} + #endif //TRACE_MEMORY_ALLOCS #ifdef TRACE_MEMORY_ALLOCS /** @brief memory block */ diff --git a/tests/unit/lib/Memory_unittest.cc b/tests/unit/lib/Memory_unittest.cc index 6f64f6cb920..93f717bd801 100644 --- a/tests/unit/lib/Memory_unittest.cc +++ b/tests/unit/lib/Memory_unittest.cc @@ -1,10 +1,11 @@ #include +#include +#include + namespace shogun { template class SGMatrix; } namespace shogun { template class SGSparseVector; } namespace shogun { template class SGVector; } -#include - using namespace shogun; TEST(MemoryTest,get_copy) @@ -54,3 +55,27 @@ TEST(MemoryTest,SGMatrix) EXPECT_NE((SGMatrix*) NULL, m); SG_FREE(m); } + +template +static void clone(T* dest, T const * const src, size_t size) +{ + shogun::memcpy(dest, src, size); +} + +TEST(MemoryTest, memcpy) +{ + const index_t size = 10; + auto src = SG_CALLOC(float64_t, size); + for (index_t i=0; i