Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "../include/MemoryProcessing.h"
#include <cstdlib>
#include <cstring>
template<>
bool dealloc<MemType::CPU>(void *&array, size_t &allocated_size)
{
if(allocated_size > 0)
{
free(array);
allocated_size = 0;
}
return true;
}
template <>
bool realloc<MemType::CPU>(void *&array, size_t &allocated_size, const size_t new_size)
{
if(new_size > allocated_size)
{
if(allocated_size > 0) dealloc<MemType::CPU>(array, allocated_size);
allocated_size = new_size;
array = malloc(new_size);
memset(array, 0, new_size);
}
return true;
}
template <>
bool memcopy<MemType::CPU, MemType::CPU>(void *dst, const void* src, const size_t copy_elem_size)
{
memcpy(dst, src, copy_elem_size);
return true;
}