Skip to content
Snippets Groups Projects
MemoryProcessing.cpp 1.2 KiB
Newer Older
数学の武士's avatar
数学の武士 committed
#include "../include/MemoryProcessing.h"
#include <cstdlib>
#include <cstring>

数学の武士's avatar
数学の武士 committed
namespace memproc
数学の武士's avatar
数学の武士 committed
{
数学の武士's avatar
数学の武士 committed
    template<>
    bool dealloc<MemType::CPU>(void *&array, size_t &allocated_size)
数学の武士's avatar
数学の武士 committed
    {
数学の武士's avatar
数学の武士 committed
        if(allocated_size > 0)
        {
            free(array);
            allocated_size = 0;
        }
数学の武士's avatar
.  
数学の武士 committed

数学の武士's avatar
数学の武士 committed
        return true;
    }
数学の武士's avatar
数学の武士 committed

数学の武士's avatar
数学の武士 committed
    template<>
    bool dealloc<MemType::CPU>(void *&array)
    {
        free(array);
        return true;
    }
数学の武士's avatar
数学の武士 committed

数学の武士's avatar
数学の武士 committed
    template <>
    bool alloc<MemType::CPU>(void *&array, const size_t new_size)
数学の武士's avatar
数学の武士 committed
    {
        array = malloc(new_size);
        memset(array, 0, new_size);
数学の武士's avatar
数学の武士 committed

        return true;
数学の武士's avatar
数学の武士 committed
    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);
数学の武士's avatar
数学の武士 committed

数学の武士's avatar
数学の武士 committed
        return true;
    }
数学の武士's avatar
数学の武士 committed
}