Skip to content
Snippets Groups Projects
MemoryProcessing.cpp 914 B
Newer Older
  • Learn to ignore specific revisions
  • 数学の武士's avatar
    数学の武士 committed
    #include "../include/MemoryProcessing.h"
    #include <cstdlib>
    #include <cstring>
    
    template<>
    
    数学の武士's avatar
    数学の武士 committed
    bool memproc::dealloc<MemType::CPU>(void *&array, size_t &allocated_size)
    
    数学の武士's avatar
    数学の武士 committed
    {
        if(allocated_size > 0)
        {
            free(array);
            allocated_size = 0;
        }
    
        return true;
    }
    
    
    数学の武士's avatar
    .  
    数学の武士 committed
    template<>
    bool memproc::dealloc<MemType::CPU>(void *&array)
    {
        free(array);
        return true;
    }
    
    
    数学の武士's avatar
    数学の武士 committed
    template <>
    
    数学の武士's avatar
    数学の武士 committed
    bool memproc::realloc<MemType::CPU>(void *&array, size_t &allocated_size, const size_t new_size)
    
    数学の武士's avatar
    数学の武士 committed
    {
        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 <>
    
    数学の武士's avatar
    数学の武士 committed
    bool memproc::memcopy<MemType::CPU, MemType::CPU>(void *dst, const void* src, const size_t copy_elem_size)
    
    数学の武士's avatar
    数学の武士 committed
    {
        memcpy(dst, src, copy_elem_size);
    
        return true;
    }