LCOV - code coverage report
Current view: top level - zerobuf - NonMovingAllocator.cpp (source / functions) Hit Total Coverage
Test: ZeroBuf Lines: 18 18 100.0 %
Date: 2018-01-09 16:38:26 Functions: 5 5 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2015, Human Brain Project
       3             :  *                     Stefan.Eilemann@epfl.ch
       4             :  *                     grigori.chevtchenko@epfl.ch
       5             :  */
       6             : 
       7             : #include "NonMovingAllocator.h"
       8             : #include <zerobuf/version.h>
       9             : 
      10             : #include <cstring>
      11             : #include <stdlib.h>
      12             : 
      13             : namespace zerobuf
      14             : {
      15         368 : NonMovingAllocator::NonMovingAllocator(const size_t staticSize,
      16         368 :                                        const size_t numDynamic)
      17             :     : NonMovingBaseAllocator(staticSize, numDynamic)
      18         368 :     , _data((uint8_t*)::calloc(1, staticSize))
      19         736 :     , _size(staticSize)
      20             : {
      21         368 : }
      22             : 
      23        1104 : NonMovingAllocator::~NonMovingAllocator()
      24             : {
      25         368 :     ::free(_data);
      26         736 : }
      27             : 
      28           5 : void NonMovingAllocator::copyBuffer(const void* data, size_t size)
      29             : {
      30           5 :     _resize(size);
      31           5 :     ::memcpy(_data, data, size);
      32           5 : }
      33             : 
      34         295 : void NonMovingAllocator::_resize(const size_t size)
      35             : {
      36         295 :     _data = (uint8_t*)::realloc(_data, size);
      37         295 :     if (size > _size)
      38             :     {
      39             : // realloc does not guarantee that additional memory is zero-filled
      40             : #ifdef _WIN32
      41             :         ::memset(_data + _size, 0, size - _size);
      42             : #else
      43         289 :         ::bzero(_data + _size, size - _size);
      44             : #endif
      45             :     }
      46         295 :     _size = size;
      47         295 : }
      48             : }

Generated by: LCOV version 1.11