8 #ifndef HEAP_MEMORY_HPP
9 #define HEAP_MEMORY_HPP
17 typedef unsigned char byte;
19 #define MEM_ALIGNMENT 32
66 virtual bool flush() {
return true;};
74 virtual size_t size()
const;
98 virtual long int ref()
152 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" destroying a live object" <<
"\n";
162 size_t alignement_tmp;
166 long int ref_cnt_tmp;
195 inline void *align( std::size_t alignment, std::size_t size,
196 void *&ptr, std::size_t &space ) {
197 std::uintptr_t pn =
reinterpret_cast< std::uintptr_t
>( ptr );
198 std::uintptr_t aligned = ( pn + alignment - 1 ) & - alignment;
199 std::size_t padding = aligned - pn;
200 if ( space < size + padding )
return nullptr;
202 return ptr =
reinterpret_cast< void *
>( aligned );
HeapMemory(HeapMemory &&mem) noexcept
void swap(HeapMemory &mem)
Swap the memory.
virtual void deviceToHost()
Do nothing.
virtual bool flush()
flush the memory
virtual bool allocate(size_t sz)
allocate memory
virtual void decRef()
Decrement the reference counter.
virtual void incRef()
Increment the reference counter.
long int ref_cnt
Reference counter.
void setAlignment(size_t align)
Set alignment the memory will be aligned with this number.
HeapMemory()
Constructor, we choose a default alignment of 32 for avx.
virtual size_t size() const
the the size of the allocated memory
This class allocate, and destroy CPU memory.
size_t alignement
memory alignment
virtual void * getPointer()
get a readable pointer with the data
virtual void destroy()
destroy memory
byte * dmOrig
original pointer (before alignment)
virtual void * getDevicePointer()
get a device pointer for HeapMemory getPointer and getDevicePointer are equivalents ...
virtual long int ref()
Return the reference counter.
virtual bool resize(size_t sz)
resize the memory allocated
bool copyFromPointer(const void *ptr, size_t sz)
copy from Pointer to Heap
bool isInitialized()
Allocated Memory is never initialized.
virtual bool copy(const memory &m)
copy memory
size_t sz
Size of the memory.
bool copyDeviceToDevice(const HeapMemory &m)
copy from same Heap to Heap