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

It is like HeapMemory but buffered. More...

Detailed Description

It is like HeapMemory but buffered.

The concept of buffer is different from allocated memory. The buffer size can be <= the allocated memory

It differs from HeapMemory in resize behavior.

In the case of BHeapMemory if you try to shrink the memory nothing happen to the allocated memory. To destroy the internal memory you must use destroy.

BHeapMemory does not shrink the memory, but it shrink the buffer size. size() always return the buffer size

Allocate memory

T mem;
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;

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(),1ul);

Definition at line 47 of file BHeapMemory.hpp.

#include <BHeapMemory.hpp>

+ Inheritance diagram for BHeapMemory:

Public Member Functions

 BHeapMemory (const BHeapMemory &mem)
 Copy the Heap memory. More...
 
 BHeapMemory (BHeapMemory &&mem) noexcept
 Copy the Heap memory. More...
 
 BHeapMemory ()
 Constructor, we choose a default alignment of 32 for avx.
 
virtual ~BHeapMemory () noexcept
 Destructor.
 
virtual bool allocate (size_t sz)
 allocate the memory More...
 
virtual bool resize (size_t sz)
 Resize the allocated memory. More...
 
virtual size_t size () const
 Resize the buffer size. More...
 
size_t msize ()
 Return the memory size. More...
 
BHeapMemoryoperator= (const BHeapMemory &mem)
 Copy the memory. More...
 
BHeapMemoryoperator= (BHeapMemory &&mem)
 Copy the memory. More...
 
void destroy ()
 Destroy the internal memory. More...
 
void swap (BHeapMemory &mem)
 swap the two mwmory object More...
 
- Public Member Functions inherited from HeapMemory
virtual bool flush ()
 flush the memory
 
virtual bool copy (const memory &m)
 copy memory 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 Attributes

size_t buf_sz
 size of the memory
 

Constructor & Destructor Documentation

BHeapMemory::BHeapMemory ( const BHeapMemory mem)
inline

Copy the Heap memory.

Parameters
memmemory to copy

Definition at line 59 of file BHeapMemory.hpp.

BHeapMemory::BHeapMemory ( BHeapMemory &&  mem)
inlinenoexcept

Copy the Heap memory.

Parameters
memmemory to copy

Definition at line 69 of file BHeapMemory.hpp.

Member Function Documentation

virtual bool BHeapMemory::allocate ( size_t  sz)
inlinevirtual

allocate the 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

Reimplemented from HeapMemory.

Definition at line 93 of file BHeapMemory.hpp.

void BHeapMemory::destroy ( )
inlinevirtual

Destroy the internal memory.

Reimplemented from HeapMemory.

Definition at line 178 of file BHeapMemory.hpp.

size_t BHeapMemory::msize ( )
inline

Return the memory size.

Returns
The allocated memory size

Definition at line 139 of file BHeapMemory.hpp.

BHeapMemory& BHeapMemory::operator= ( const BHeapMemory mem)
inline

Copy the memory.

Parameters
memmemory to copy
Returns
itself

Definition at line 151 of file BHeapMemory.hpp.

BHeapMemory& BHeapMemory::operator= ( BHeapMemory &&  mem)
inline

Copy the memory.

Parameters
memmemory to copy
Returns
itself

Definition at line 166 of file BHeapMemory.hpp.

virtual bool BHeapMemory::resize ( size_t  sz)
inlinevirtual

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

Reimplemented from HeapMemory.

Definition at line 112 of file BHeapMemory.hpp.

virtual size_t BHeapMemory::size ( ) const
inlinevirtual

Resize the buffer size.

Returns
the buffer size

Reimplemented from HeapMemory.

Definition at line 128 of file BHeapMemory.hpp.

void BHeapMemory::swap ( BHeapMemory mem)
inline

swap the two mwmory object

Parameters
memMemory to swap with

Definition at line 189 of file BHeapMemory.hpp.


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