OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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
18typedef unsigned char byte;
19
20#define MEM_ALIGNMENT 32
21
45template<typename Memory>
46class BMemory : public Memory
47{
49 size_t buf_sz;
50
51public:
52
59 :Memory(mem),buf_sz(mem.size())
60 {
61 }
62
68 BMemory(BMemory<Memory> && mem) noexcept
69 :Memory((Memory &&)mem),buf_sz(mem.size())
70 {
71 }
72
75 :Memory(),buf_sz(0)
76 {};
77
79 virtual ~BMemory() noexcept
80 {
81 };
82
92 virtual bool allocate(size_t sz)
93 {
94 bool ret = Memory::allocate(sz);
95
96 if (ret == true)
97 buf_sz = sz;
98
99 return ret;
100 }
101
111 virtual bool resize(size_t sz)
112 {
113 bool ret = Memory::resize(sz);
114
115 // if the allocated memory is enough, do not resize
116 if (ret == true)
117 buf_sz = sz;
118
119 return ret;
120 }
121
127 virtual size_t size() const
128 {
129 return buf_sz;
130 }
131
138 size_t msize()
139 {
140 return Memory::size();
141 }
142
151 {
152 buf_sz = mem.buf_sz;
153 static_cast<Memory *>(this)->operator=(mem);
154
155 return *this;
156 }
157
166 {
167 buf_sz = mem.buf_sz;
168 static_cast<Memory *>(this)->operator=(mem);
169
170 return *this;
171 }
172
177 void destroy()
178 {
179 Memory::destroy();
180 buf_sz = 0;
181 }
182
189 {
190 Memory::swap(mem);
191
192 size_t buf_sz_t = mem.buf_sz;
193 mem.buf_sz = buf_sz;
194 buf_sz = buf_sz_t;
195 }
196};
197
198
199#endif
It override the behavior if size()
BMemory & operator=(BMemory< Memory > &&mem)
Copy the memory.
void swap(BMemory< Memory > &mem)
swap the two memory object
virtual ~BMemory() noexcept
Destructor.
virtual bool allocate(size_t sz)
allocate the memory
BMemory(const BMemory< Memory > &mem)
Copy the Heap memory.
BMemory & operator=(const BMemory< Memory > &mem)
Copy the memory.
virtual bool resize(size_t sz)
Resize the allocated memory.
BMemory()
Constructor, we choose a default alignment of 32 for avx.
size_t msize()
Return the memory size.
size_t buf_sz
size of the memory
BMemory(BMemory< Memory > &&mem) noexcept
Copy the Heap memory.
void destroy()
Destroy the internal memory.
virtual size_t size() const
Resize the buffer size.