OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
BHeapMemory.hpp
1 /*
2  * RHeapMempory.hpp
3  *
4  * Created on: Aug 17, 2014
5  * Author: Pietro Incardona
6  */
7 
8 
9 #ifndef BHEAP_MEMORY_HPP
10 #define BHEAP_MEMORY_HPP
11 
12 #include "config.h"
13 #include "memory.hpp"
14 #include <cstddef>
15 #include <cstdint>
16 #include <iostream>
17 
18 typedef unsigned char byte;
19 
20 #define MEM_ALIGNMENT 32
21 
47 class BHeapMemory : public HeapMemory
48 {
50  size_t buf_sz;
51 
52 public:
53 
59  BHeapMemory(const BHeapMemory & mem)
60  :HeapMemory(mem),buf_sz(mem.size())
61  {
62  }
63 
69  BHeapMemory(BHeapMemory && mem) noexcept
70  :HeapMemory((HeapMemory &&)mem),buf_sz(mem.size())
71  {
72  }
73 
76  :HeapMemory(),buf_sz(0)
77  {};
78 
80  virtual ~BHeapMemory() noexcept
81  {
82  };
83 
93  virtual bool allocate(size_t sz)
94  {
95  bool ret = HeapMemory::allocate(sz);
96 
97  if (ret == true)
98  buf_sz = sz;
99 
100  return ret;
101  }
102 
112  virtual bool resize(size_t sz)
113  {
114  bool ret = HeapMemory::resize(sz);
115 
116  // if the allocated memory is enough, do not resize
117  if (ret == true)
118  buf_sz = sz;
119 
120  return ret;
121  }
122 
128  virtual size_t size() const
129  {
130  return buf_sz;
131  }
132 
139  size_t msize()
140  {
141  return HeapMemory::size();
142  }
143 
152  {
153  buf_sz = mem.buf_sz;
154  static_cast<HeapMemory *>(this)->operator=(mem);
155 
156  return *this;
157  }
158 
167  {
168  buf_sz = mem.buf_sz;
169  static_cast<HeapMemory *>(this)->operator=(mem);
170 
171  return *this;
172  }
173 
178  void destroy()
179  {
181  buf_sz = 0;
182  }
183 
189  void swap(BHeapMemory & mem)
190  {
191  HeapMemory::swap(mem);
192 
193  size_t buf_sz_t = mem.buf_sz;
194  mem.buf_sz = buf_sz;
195  buf_sz = buf_sz_t;
196  }
197 };
198 
199 
200 #endif
void swap(HeapMemory &mem)
Swap the memory.
Definition: HeapMemory.hpp:160
BHeapMemory(const BHeapMemory &mem)
Copy the Heap memory.
Definition: BHeapMemory.hpp:59
BHeapMemory(BHeapMemory &&mem) noexcept
Copy the Heap memory.
Definition: BHeapMemory.hpp:69
virtual bool allocate(size_t sz)
allocate memory
Definition: HeapMemory.cpp:27
virtual bool allocate(size_t sz)
allocate the memory
Definition: BHeapMemory.hpp:93
virtual ~BHeapMemory() noexcept
Destructor.
Definition: BHeapMemory.hpp:80
BHeapMemory & operator=(BHeapMemory &&mem)
Copy the memory.
virtual size_t size() const
Resize the buffer size.
virtual size_t size() const
the the size of the allocated memory
Definition: HeapMemory.cpp:157
This class allocate, and destroy CPU memory.
Definition: HeapMemory.hpp:39
It is like HeapMemory but buffered.
Definition: BHeapMemory.hpp:47
size_t buf_sz
size of the memory
Definition: BHeapMemory.hpp:50
virtual void destroy()
destroy memory
Definition: HeapMemory.cpp:63
BHeapMemory & operator=(const BHeapMemory &mem)
Copy the memory.
size_t msize()
Return the memory size.
void swap(BHeapMemory &mem)
swap the two mwmory object
virtual bool resize(size_t sz)
Resize the allocated memory.
virtual bool resize(size_t sz)
resize the memory allocated
Definition: HeapMemory.cpp:171
BHeapMemory()
Constructor, we choose a default alignment of 32 for avx.
Definition: BHeapMemory.hpp:75
void destroy()
Destroy the internal memory.
size_t sz
Size of the memory.
Definition: HeapMemory.hpp:45