Psyllid  v1.12.4
Project 8 Data Acquisisition Software
memory_block.cc
Go to the documentation of this file.
1 /*
2  * memory_block.cc
3  *
4  * Created on: Nov 2, 2016
5  * Author: nsoblath
6  */
7 
8 #include "memory_block.hh"
9 
10 #include <cstdlib>
11 
12 namespace psyllid
13 {
14 
16  f_n_bytes( 0 ),
17  f_n_bytes_used( 0 ),
18  f_block( nullptr )
19  {
20  }
21 
23  {
24  if( f_n_bytes != 0 ) free( (void*)f_block );
25  }
26 
27  void memory_block::resize( size_t a_n_bytes )
28  {
29  if( a_n_bytes == f_n_bytes ) return;
30  if( f_n_bytes != 0 ) ::free( (void*)f_block );
31  if( a_n_bytes != 0 ) f_block = (uint8_t*)::malloc( a_n_bytes );
32  else f_block = nullptr;
33  f_n_bytes = a_n_bytes;
34  return;
35  }
36 
37 } /* namespace psyllid */
void resize(size_t a_n_bytes)
Definition: memory_block.cc:27