OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
HeapMemory Class Reference

This class allocate, and destroy CPU memory. More...

Detailed Description

This class allocate, and destroy CPU memory.

Allocate memory

T mem;
BOOST_REQUIRE_EQUAL(mem.size(),0ul);
mem.allocate(FIRST_ALLOCATION);
BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION);
// get the pointer of the allocated memory and fill
unsigned char * ptr = (unsigned char *)mem.getPointer();
for (size_t i = 0 ; i < mem.size() ; i++)
{ptr[i] = i;}
mem.flush();

Resize memory

mem.resize(SECOND_ALLOCATION);
unsigned char * ptr2 = (unsigned char *)mem.getPointer();
BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION);
BOOST_REQUIRE_EQUAL(mem.isInitialized(),false);

Shrink memory

mem.resize(1);
BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION);

Definition at line 39 of file HeapMemory.hpp.

#include <HeapMemory.hpp>

+ Inheritance diagram for HeapMemory:

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 device pointer for HeapMemory getPointer and getDevicePointer are equivalents 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 never initialized. More...
 
HeapMemoryoperator= (const HeapMemory &mem)
 
 HeapMemory (const HeapMemory &mem)
 
 HeapMemory (HeapMemory &&mem) noexcept
 
 HeapMemory ()
 Constructor, we choose a default alignment of 32 for avx.
 
void swap (HeapMemory &mem)
 Swap the memory. More...
 
- Public Member Functions inherited from memory
virtual ~memory ()
 destructor More...
 

Private Member Functions

bool copyDeviceToDevice (const HeapMemory &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. More...
 

Private Attributes

size_t alignement
 memory alignment
 
size_t sz
 Size of the memory.
 
byte * dm
 device memory
 
byte * dmOrig
 original pointer (before alignment)
 
long int ref_cnt
 Reference counter.
 

Constructor & Destructor Documentation

HeapMemory::HeapMemory ( HeapMemory &&  mem)
inlinenoexcept

move

Definition at line 128 of file HeapMemory.hpp.

Member Function Documentation

bool HeapMemory::allocate ( size_t  sz)
virtual

allocate memory

Allocate a chunk of memory.

Parameters
szsize of the chunk of memory to allocate in byte

Allocate the device memory

Implements memory.

Reimplemented in BHeapMemory.

Definition at line 27 of file HeapMemory.cpp.

bool HeapMemory::copy ( const memory m)
virtual

copy memory

copy the memory

Parameters
ma memory interface

Here we try to cast memory into HeapMemory

if we fail we get the pointer and simply copy from the pointer

Implements memory.

Definition at line 127 of file HeapMemory.cpp.

bool HeapMemory::copyDeviceToDevice ( const HeapMemory m)
private

copy from same Heap to Heap

copy from device to device

copy a piece of memory from device to device

Parameters
mfrom where to copy

The source buffer is too big to copy it

Definition at line 103 of file HeapMemory.cpp.

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

copy from Pointer to Heap

copy the data from a pointer

Parameters
ptr

Definition at line 83 of file HeapMemory.cpp.

void HeapMemory::destroy ( )
virtual

destroy memory

Destroy the internal memory.

Implements memory.

Reimplemented in BHeapMemory.

Definition at line 63 of file HeapMemory.cpp.

void * HeapMemory::getDevicePointer ( )
virtual

get a device pointer for HeapMemory getPointer and getDevicePointer are equivalents

Return a readable pointer with your data.

Return a readable pointer with your data

Implements memory.

Definition at line 226 of file HeapMemory.cpp.

void * HeapMemory::getPointer ( )
virtual

get a readable pointer with the data

Return a readable pointer with your data.

Return a readable pointer with your data

Implements memory.

Definition at line 237 of file HeapMemory.cpp.

const void * HeapMemory::getPointer ( ) const
virtual

get a readable pointer with the data

Return a readable pointer with your data.

Return a readable pointer with your data

Implements memory.

Definition at line 248 of file HeapMemory.cpp.

bool HeapMemory::isInitialized ( )
inlinevirtual

Allocated Memory is never initialized.

Returns
false

Implements memory.

Definition at line 108 of file HeapMemory.hpp.

bool HeapMemory::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

Allocate the device memory if not done yet

Create a new buffer if sz is bigger than the actual size

size plus alignment

align it

copy from the old buffer to the new one

free the old buffer

change to the new buffer

Implements memory.

Reimplemented in BHeapMemory.

Definition at line 171 of file HeapMemory.cpp.

void HeapMemory::setAlignment ( size_t  align)
private

Set alignment the memory will be aligned with this number.

set the memory block to be aligned by this number

Definition at line 54 of file HeapMemory.cpp.

size_t HeapMemory::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.

Reimplemented in BHeapMemory.

Definition at line 157 of file HeapMemory.cpp.

void HeapMemory::swap ( HeapMemory mem)
inline

Swap the memory.

Parameters
memmemory to swap

Definition at line 160 of file HeapMemory.hpp.


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