OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
PtrMemory Class Reference

This class give memory from a preallocated memory, memory destruction is not performed. More...

Detailed Description

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 39 of file PtrMemory.hpp.

#include <PtrMemory.hpp>

+ Inheritance diagram for PtrMemory:

Public Member Functions

bool copyDeviceToDevice (const PtrMemory &m)
 copy from same Heap to Heap
 
virtual bool flush ()
 flush the memory
 
virtual bool allocate (size_t sz)
 allocate memory
 
virtual void destroy ()
 destroy memory
 
virtual bool copy (const memory &m)
 copy memory
 
virtual size_t size () const
 the the size of the allocated memory
 
virtual bool resize (size_t sz)
 resize the memory allocated
 
virtual void * getPointer ()
 get a readable pointer with the data
 
virtual const void * getPointer () const
 get a readable pointer with the data
 
virtual void * getDevicePointer ()
 get a readable pointer with the data
 
virtual void deviceToHost ()
 Do nothing.
 
virtual void hostToDevice ()
 Do nothing.
 
virtual void deviceToHost (size_t start, size_t stop)
 Do nothing.
 
virtual void hostToDevice (size_t start, size_t top)
 Do nothing.
 
virtual void fill (unsigned char c)
 fill memory with the selected byte
 
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.
 
 PtrMemory (void *ptr, size_t sz)
 Constructor, we choose a default alignment of 32 for avx.
 
- Public Member Functions inherited from memory
virtual ~memory ()
 destructor
 

Static Public Member Functions

static constexpr bool isDeviceHostSame ()
 Return true if the device and the host pointer are the same.
 

Private Member Functions

bool copyFromPointer (const void *ptr, size_t sz)
 copy from Pointer to Heap
 
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.
 

Constructor & Destructor Documentation

◆ PtrMemory() [1/2]

PtrMemory::PtrMemory ( )
inline

Definition at line 136 of file PtrMemory.hpp.

◆ PtrMemory() [2/2]

PtrMemory::PtrMemory ( void *  ptr,
size_t  sz 
)
inline

Constructor, we choose a default alignment of 32 for avx.

Definition at line 141 of file PtrMemory.hpp.

◆ ~PtrMemory()

PtrMemory::~PtrMemory ( )
inline

Definition at line 145 of file PtrMemory.hpp.

Member Function Documentation

◆ allocate()

bool PtrMemory::allocate ( size_t  sz)
virtual

allocate memory

Allocate a chunk of memory.

Parameters
szsize of the chunk of memory to allocate in byte

Implements memory.

Definition at line 33 of file PtrMemory.cpp.

◆ copy()

bool PtrMemory::copy ( const memory m)
virtual

copy memory

copy the memory

Parameters
ma 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 92 of file PtrMemory.cpp.

◆ copyDeviceToDevice()

bool PtrMemory::copyDeviceToDevice ( const PtrMemory m)

copy from same Heap to Heap

copy from device to device

copy a piece of memory from device to device

Parameters
mPtrMemory from where to copy
Returns
true if the memory is successful copy

The source buffer is too big to copy it

Definition at line 72 of file PtrMemory.cpp.

◆ copyFromPointer()

bool PtrMemory::copyFromPointer ( const void *  ptr,
size_t  sz 
)
private

copy from Pointer to Heap

copy the data from a pointer

Parameters
ptr

Definition at line 54 of file PtrMemory.cpp.

◆ decRef()

virtual void PtrMemory::decRef ( )
inlinevirtual

Decrement the reference counter.

Implements memory.

Definition at line 106 of file PtrMemory.hpp.

◆ destroy()

void PtrMemory::destroy ( )
virtual

destroy memory

destroy a chunk of memory

Implements memory.

Definition at line 45 of file PtrMemory.cpp.

◆ deviceToHost() [1/2]

virtual void PtrMemory::deviceToHost ( )
inlinevirtual

Do nothing.

Implements memory.

Definition at line 84 of file PtrMemory.hpp.

◆ deviceToHost() [2/2]

virtual void PtrMemory::deviceToHost ( size_t  start,
size_t  stop 
)
inlinevirtual

Do nothing.

Implements memory.

Definition at line 90 of file PtrMemory.hpp.

◆ fill()

void PtrMemory::fill ( unsigned char  c)
virtual

fill memory with the selected byte

Parameters
byteto fill

Implements memory.

Definition at line 22 of file PtrMemory.cpp.

◆ flush()

virtual bool PtrMemory::flush ( )
inlinevirtual

flush the memory

Implements memory.

Definition at line 62 of file PtrMemory.hpp.

◆ getDevicePointer()

void * PtrMemory::getDevicePointer ( )
virtual

get a readable pointer with the data

Return a pointer to the allocated memory.

Returns
the pointer

Implements memory.

Definition at line 167 of file PtrMemory.cpp.

◆ getPointer() [1/2]

void * PtrMemory::getPointer ( )
virtual

get a readable pointer with the data

Return a pointer to the allocated memory.

Returns
the pointer

Implements memory.

Definition at line 156 of file PtrMemory.cpp.

◆ getPointer() [2/2]

const void * PtrMemory::getPointer ( ) const
virtual

get a readable pointer with the data

Return a pointer to the allocated memory.

Returns
the pointer

Implements memory.

Definition at line 179 of file PtrMemory.cpp.

◆ hostToDevice() [1/2]

virtual void PtrMemory::hostToDevice ( )
inlinevirtual

Do nothing.

Implements memory.

Definition at line 87 of file PtrMemory.hpp.

◆ hostToDevice() [2/2]

virtual void PtrMemory::hostToDevice ( size_t  start,
size_t  top 
)
inlinevirtual

Do nothing.

Implements memory.

Definition at line 93 of file PtrMemory.hpp.

◆ incRef()

virtual void PtrMemory::incRef ( )
inlinevirtual

Increment the reference counter.

Implements memory.

Definition at line 102 of file PtrMemory.hpp.

◆ isDeviceHostSame()

static constexpr bool PtrMemory::isDeviceHostSame ( )
inlinestaticconstexpr

Return true if the device and the host pointer are the same.

Returns
true if they are the same

Definition at line 120 of file PtrMemory.hpp.

◆ isInitialized()

bool PtrMemory::isInitialized ( )
inlinevirtual

Allocated Memory is already initialized.

Returns
true

Implements memory.

Definition at line 130 of file PtrMemory.hpp.

◆ ref()

virtual long int PtrMemory::ref ( )
inlinevirtual

Return the reference counter.

Implements memory.

Definition at line 110 of file PtrMemory.hpp.

◆ resize()

bool PtrMemory::resize ( size_t  sz)
virtual

resize the memory allocated

Resize the allocated memory.

Resize the allocated memory, if request is smaller than the allocated memory is not resized

Parameters
szsize
Returns
true if the resize operation complete correctly

Implements memory.

Definition at line 137 of file PtrMemory.cpp.

◆ size()

size_t PtrMemory::size ( ) const
virtual

the the size of the allocated memory

Get the size of the allocated memory.

Get the size of the allocated memory

Returns
the size of the allocated memory

Implements memory.

Definition at line 122 of file PtrMemory.cpp.

Field Documentation

◆ dm

void* PtrMemory::dm
private

Pointed memory.

Definition at line 45 of file PtrMemory.hpp.

◆ ref_cnt

long int PtrMemory::ref_cnt
private

Reference counter.

Definition at line 48 of file PtrMemory.hpp.

◆ spm

size_t PtrMemory::spm
private

Size of the pointed memory.

Definition at line 42 of file PtrMemory.hpp.


The documentation for this class was generated from the following files: