This class give memory from a preallocated memory, memory destruction is not performed. More...
This class give memory from a preallocated memory, memory destruction is not performed.
Useful to shape pieces of memory
Usage:
void * ptr = new int[1000]
PtrMemory m = new PtrMemory(ptr,1000);
m.allocate(); int * ptr = m.getPointer(); *ptr[999] = 1000; ....
delete[] ptr;
Definition at line 42 of file PtrMemory.hpp.
#include <PtrMemory.hpp>
Public Member Functions | |
virtual bool | flush () |
flush the memory | |
virtual bool | allocate (size_t sz) |
allocate memory More... | |
virtual void | destroy () |
destroy memory More... | |
virtual bool | copy (const memory &m) |
copy memory More... | |
virtual size_t | size () const |
the the size of the allocated memory More... | |
virtual bool | resize (size_t sz) |
resize the memory allocated More... | |
virtual void * | getPointer () |
get a readable pointer with the data More... | |
virtual const void * | getPointer () const |
get a readable pointer with the data More... | |
virtual void * | getDevicePointer () |
get a readable pointer with the data More... | |
virtual void | deviceToHost () |
Do nothing. | |
virtual void | incRef () |
Increment the reference counter. | |
virtual void | decRef () |
Decrement the reference counter. | |
virtual long int | ref () |
Return the reference counter. | |
bool | isInitialized () |
Allocated Memory is already initialized. More... | |
PtrMemory (void *ptr, size_t sz) | |
Constructor, we choose a default alignment of 32 for avx. | |
![]() | |
virtual | ~memory () |
destructor More... | |
Private Member Functions | |
bool | copyDeviceToDevice (const PtrMemory &m) |
copy from same Heap to Heap More... | |
bool | copyFromPointer (const void *ptr, size_t sz) |
copy from Pointer to Heap More... | |
void | setAlignment (size_t align) |
Set alignment the memory will be aligned with this number. | |
Private Attributes | |
size_t | spm |
Size of the pointed memory. | |
void * | dm |
Pointed memory. | |
long int | ref_cnt |
Reference counter. | |
|
virtual |
allocate memory
Allocate a chunk of memory.
sz | size of the chunk of memory to allocate in byte |
Implements memory.
Definition at line 28 of file PtrMemory.cpp.
|
virtual |
copy memory
copy the memory
m | a memory interface |
Here we try to cast memory into PtrMemory
if we fail we get the pointer and simply copy from the pointer
Implements memory.
Definition at line 87 of file PtrMemory.cpp.
|
private |
copy from same Heap to Heap
copy from device to device
copy a piece of memory from device to device
m | PtrMemory from where to copy |
The source buffer is too big to copy it
Definition at line 67 of file PtrMemory.cpp.
|
private |
copy from Pointer to Heap
copy the data from a pointer
ptr |
Definition at line 49 of file PtrMemory.cpp.
|
virtual |
destroy memory
destroy a chunk of memory
Implements memory.
Definition at line 40 of file PtrMemory.cpp.
|
virtual |
get a readable pointer with the data
Return a pointer to the allocated memory.
Implements memory.
Definition at line 162 of file PtrMemory.cpp.
|
virtual |
get a readable pointer with the data
Return a pointer to the allocated memory.
Implements memory.
Definition at line 151 of file PtrMemory.cpp.
|
virtual |
get a readable pointer with the data
Return a pointer to the allocated memory.
Implements memory.
Definition at line 174 of file PtrMemory.cpp.
|
inlinevirtual |
Allocated Memory is already initialized.
Implements memory.
Definition at line 107 of file PtrMemory.hpp.
|
virtual |
resize the memory allocated
Resize the allocated memory.
Resize the allocated memory, if request is smaller than the allocated memory is not resized
sz | size |
Implements memory.
Definition at line 132 of file PtrMemory.cpp.
|
virtual |
the the size of the allocated memory
Get the size of the allocated memory.
Get the size of the allocated memory
Implements memory.
Definition at line 117 of file PtrMemory.cpp.