OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
ExtPreAlloc< Mem > Class Template Reference

Detailed Description

template<typename Mem>
class ExtPreAlloc< Mem >

Preallocated memory sequence

External pre-allocated memory, is a class that preallocate memory and than it answer to a particular allocation pattern

Warning
zero sized allocation are removed from the request pattern
Template Parameters
Basememory allocation class [Example] HeapMemory or CudaMemory

Definition at line 27 of file ExtPreAlloc.hpp.

#include <ExtPreAlloc.hpp>

+ Inheritance diagram for ExtPreAlloc< Mem >:

Public Member Functions

 ExtPreAlloc ()
 Default constructor.
 
 ExtPreAlloc (size_t size, Mem &mem)
 Preallocated memory sequence.
 
void setMemory (size_t size, Mem &mem)
 Set the internal memory if you did not do it in the constructor.
 
Mem * getMemory ()
 Get the internal memory if you did not do it in the constructor.
 
bool copyDeviceToDevice (const ExtPreAlloc< Mem > &m)
 Copy the memory from device to device.
 
void deviceToDevice (void *ptr, size_t start, size_t stop, size_t offset)
 special function to move memory from a raw device pointer
 
virtual void incRef ()
 Increment the reference counter.
 
virtual void decRef ()
 Decrement the reference counter.
 
virtual long int ref ()
 Return the reference counter.
 
virtual bool flush ()
 flush the memory
 
virtual void fill (unsigned char c)
 fill host and device memory with the selected byte
 
virtual bool allocate (size_t sz)
 Allocate a chunk of memory.
 
bool allocate_nocheck (size_t sz)
 Allocate a chunk of memory.
 
void * getPointerEnd ()
 Return the end pointer of the previous allocated memory.
 
void * getDevicePointerEnd ()
 Return the device end pointer of the previous allocated memory.
 
void * getPointerBase ()
 The the base pointer of the preallocate memory.
 
virtual void * getDevicePointer ()
 Return the pointer of the last allocation.
 
virtual void hostToDevice ()
 Return the pointer of the last allocation.
 
virtual void hostToDevice (size_t start, size_t stop)
 Return the pointer of the last allocation.
 
virtual void deviceToHost ()
 Do nothing.
 
virtual void deviceToHost (size_t start, size_t stop)
 Do nothing.
 
virtual void * getPointer ()
 Return the pointer of the last allocation.
 
virtual const void * getPointer () const
 Return the pointer of the last allocation.
 
void * getPointerOffset (size_t offset)
 Get the base memory pointer increased with an offset.
 
virtual bool resize (size_t sz)
 Allocate or resize the allocated memory.
 
virtual size_t size () const
 Get the size of the LAST allocated memory.
 
void destroy ()
 Destroy memory.
 
virtual bool copy (const memory &m)
 Copy memory.
 
bool isInitialized ()
 Allocated Memory is never initialized.
 
void shift_backward (size_t sz)
 shift the pointer backward
 
void shift_forward (size_t sz)
 shift the pointer forward
 
size_t getOffset ()
 Get offset.
 
size_t getOffsetEnd ()
 Get offset.
 
void reset ()
 Reset the internal counters.
 
- Public Member Functions inherited from memory
virtual ~memory ()
 destructor
 

Static Public Member Functions

static constexpr bool isDeviceHostSame ()
 
static size_t calculateMem (std::vector< size_t > &mm)
 Calculate the total memory required to pack the message.
 

Private Attributes

size_t a_seq
 Actual allocation pointer.
 
size_t l_size
 Last allocation size.
 
Mem * mem
 Main class for memory allocation.
 
long int ref_cnt
 Reference counter.
 

Constructor & Destructor Documentation

◆ ~ExtPreAlloc()

template<typename Mem >
virtual ExtPreAlloc< Mem >::~ExtPreAlloc ( )
inlinevirtual

Definition at line 43 of file ExtPreAlloc.hpp.

◆ ExtPreAlloc() [1/2]

template<typename Mem >
ExtPreAlloc< Mem >::ExtPreAlloc ( )
inline

Default constructor.

Definition at line 50 of file ExtPreAlloc.hpp.

◆ ExtPreAlloc() [2/2]

template<typename Mem >
ExtPreAlloc< Mem >::ExtPreAlloc ( size_t  size,
Mem &  mem 
)
inline

Preallocated memory sequence.

Parameters
sizenumber of bytes
memexternal memory, used if you want to keep the memory

Definition at line 61 of file ExtPreAlloc.hpp.

Member Function Documentation

◆ allocate()

template<typename Mem >
virtual bool ExtPreAlloc< Mem >::allocate ( size_t  sz)
inlinevirtual

Allocate a chunk of memory.

Allocate a chunk of memory

Parameters
szsize of the chunk of memory to allocate in byte

Implements memory.

Definition at line 151 of file ExtPreAlloc.hpp.

◆ allocate_nocheck()

template<typename Mem >
bool ExtPreAlloc< Mem >::allocate_nocheck ( size_t  sz)
inline

Allocate a chunk of memory.

Allocate a chunk of memory

Parameters
szsize of the chunk of memory to allocate in byte

Definition at line 178 of file ExtPreAlloc.hpp.

◆ calculateMem()

template<typename Mem >
static size_t ExtPreAlloc< Mem >::calculateMem ( std::vector< size_t > &  mm)
inlinestatic

Calculate the total memory required to pack the message.

Returns
the total required memory

Definition at line 357 of file ExtPreAlloc.hpp.

◆ copy()

template<typename Mem >
virtual bool ExtPreAlloc< Mem >::copy ( const memory m)
inlinevirtual

Copy memory.

Implements memory.

Definition at line 337 of file ExtPreAlloc.hpp.

◆ copyDeviceToDevice()

template<typename Mem >
bool ExtPreAlloc< Mem >::copyDeviceToDevice ( const ExtPreAlloc< Mem > &  m)
inline

Copy the memory from device to device.

Parameters
mmemory from where to copy

Definition at line 95 of file ExtPreAlloc.hpp.

◆ decRef()

template<typename Mem >
virtual void ExtPreAlloc< Mem >::decRef ( )
inlinevirtual

Decrement the reference counter.

Implements memory.

Definition at line 123 of file ExtPreAlloc.hpp.

◆ destroy()

template<typename Mem >
void ExtPreAlloc< Mem >::destroy ( )
inlinevirtual

Destroy memory.

Implements memory.

Definition at line 328 of file ExtPreAlloc.hpp.

◆ deviceToDevice()

template<typename Mem >
void ExtPreAlloc< Mem >::deviceToDevice ( void *  ptr,
size_t  start,
size_t  stop,
size_t  offset 
)
inline

special function to move memory from a raw device pointer

Parameters
startbyte
stopbyte
offsetdestination byte

Definition at line 108 of file ExtPreAlloc.hpp.

◆ deviceToHost() [1/2]

template<typename Mem >
virtual void ExtPreAlloc< Mem >::deviceToHost ( )
inlinevirtual

Do nothing.

Implements memory.

Definition at line 255 of file ExtPreAlloc.hpp.

◆ deviceToHost() [2/2]

template<typename Mem >
virtual void ExtPreAlloc< Mem >::deviceToHost ( size_t  start,
size_t  stop 
)
inlinevirtual

Do nothing.

Implements memory.

Definition at line 261 of file ExtPreAlloc.hpp.

◆ fill()

template<typename Mem >
virtual void ExtPreAlloc< Mem >::fill ( unsigned char  c)
inlinevirtual

fill host and device memory with the selected byte

Implements memory.

Definition at line 139 of file ExtPreAlloc.hpp.

◆ flush()

template<typename Mem >
virtual bool ExtPreAlloc< Mem >::flush ( )
inlinevirtual

flush the memory

Implements memory.

Definition at line 133 of file ExtPreAlloc.hpp.

◆ getDevicePointer()

template<typename Mem >
virtual void * ExtPreAlloc< Mem >::getDevicePointer ( )
inlinevirtual

Return the pointer of the last allocation.

NULL if memory has not been allocated

Returns
the pointer

Implements memory.

Definition at line 227 of file ExtPreAlloc.hpp.

◆ getDevicePointerEnd()

template<typename Mem >
void * ExtPreAlloc< Mem >::getDevicePointerEnd ( )
inline

Return the device end pointer of the previous allocated memory.

Returns
the pointer

Definition at line 205 of file ExtPreAlloc.hpp.

◆ getMemory()

template<typename Mem >
Mem * ExtPreAlloc< Mem >::getMemory ( )
inline

Get the internal memory if you did not do it in the constructor.

Returns
the internal memory

Definition at line 85 of file ExtPreAlloc.hpp.

◆ getOffset()

template<typename Mem >
size_t ExtPreAlloc< Mem >::getOffset ( )
inline

Get offset.

Returns
the offset

Definition at line 429 of file ExtPreAlloc.hpp.

◆ getOffsetEnd()

template<typename Mem >
size_t ExtPreAlloc< Mem >::getOffsetEnd ( )
inline

Get offset.

Returns
the offset

Definition at line 439 of file ExtPreAlloc.hpp.

◆ getPointer() [1/2]

template<typename Mem >
virtual void * ExtPreAlloc< Mem >::getPointer ( )
inlinevirtual

Return the pointer of the last allocation.

Returns
the pointer

Implements memory.

Definition at line 271 of file ExtPreAlloc.hpp.

◆ getPointer() [2/2]

template<typename Mem >
virtual const void * ExtPreAlloc< Mem >::getPointer ( ) const
inlinevirtual

Return the pointer of the last allocation.

Returns
the pointer

Implements memory.

Definition at line 281 of file ExtPreAlloc.hpp.

◆ getPointerBase()

template<typename Mem >
void * ExtPreAlloc< Mem >::getPointerBase ( )
inline

The the base pointer of the preallocate memory.

Returns
the base pointer

Definition at line 215 of file ExtPreAlloc.hpp.

◆ getPointerEnd()

template<typename Mem >
void * ExtPreAlloc< Mem >::getPointerEnd ( )
inline

Return the end pointer of the previous allocated memory.

Returns
the pointer

Definition at line 195 of file ExtPreAlloc.hpp.

◆ getPointerOffset()

template<typename Mem >
void * ExtPreAlloc< Mem >::getPointerOffset ( size_t  offset)
inline

Get the base memory pointer increased with an offset.

Parameters
offsetmemory offset

Definition at line 291 of file ExtPreAlloc.hpp.

◆ hostToDevice() [1/2]

template<typename Mem >
virtual void ExtPreAlloc< Mem >::hostToDevice ( )
inlinevirtual

Return the pointer of the last allocation.

Returns
the pointer

Implements memory.

Definition at line 239 of file ExtPreAlloc.hpp.

◆ hostToDevice() [2/2]

template<typename Mem >
virtual void ExtPreAlloc< Mem >::hostToDevice ( size_t  start,
size_t  stop 
)
inlinevirtual

Return the pointer of the last allocation.

Returns
the pointer

Implements memory.

Definition at line 249 of file ExtPreAlloc.hpp.

◆ incRef()

template<typename Mem >
virtual void ExtPreAlloc< Mem >::incRef ( )
inlinevirtual

Increment the reference counter.

Implements memory.

Definition at line 119 of file ExtPreAlloc.hpp.

◆ isDeviceHostSame()

template<typename Mem >
static constexpr bool ExtPreAlloc< Mem >::isDeviceHostSame ( )
inlinestaticconstexpr

Definition at line 113 of file ExtPreAlloc.hpp.

◆ isInitialized()

template<typename Mem >
bool ExtPreAlloc< Mem >::isInitialized ( )
inlinevirtual

Allocated Memory is never initialized.

Returns
false

Implements memory.

Definition at line 347 of file ExtPreAlloc.hpp.

◆ ref()

template<typename Mem >
virtual long int ExtPreAlloc< Mem >::ref ( )
inlinevirtual

Return the reference counter.

Implements memory.

Definition at line 127 of file ExtPreAlloc.hpp.

◆ reset()

template<typename Mem >
void ExtPreAlloc< Mem >::reset ( )
inline

Reset the internal counters.

Definition at line 448 of file ExtPreAlloc.hpp.

◆ resize()

template<typename Mem >
virtual bool ExtPreAlloc< Mem >::resize ( size_t  sz)
inlinevirtual

Allocate or 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 306 of file ExtPreAlloc.hpp.

◆ setMemory()

template<typename Mem >
void ExtPreAlloc< Mem >::setMemory ( size_t  size,
Mem &  mem 
)
inline

Set the internal memory if you did not do it in the constructor.

Parameters
sizenumber of bytes
memexternal memory, used if you want to keep the memory

Definition at line 74 of file ExtPreAlloc.hpp.

◆ shift_backward()

template<typename Mem >
void ExtPreAlloc< Mem >::shift_backward ( size_t  sz)
inline

shift the pointer backward

Warning
when you shift backward the pointer, the last allocation is lost this mean that you have to do again an allocation.

This function is useful to go ahead in memory and fill the memory later on

mem.allocate(16); <------ Here we allocate 16 byte but we do not fill it because
subsequently we do another allocation without using mem
unsigned char * start = (unsigned char *)mem.getPointer()
// ...
// ...
// Code that fill mem in some way and do other mem.allocate(...)
// ...
// ...
unsigned char * final = (unsigned char *)mem.getPointer()
mem.shift_backward(final - start);
mem.allocate(16); <------ Here I am getting the same memory that I request for the
first allocate
// we now fill the memory
virtual void fill(unsigned char c)
fill host and device memory with the selected byte
Mem * mem
Main class for memory allocation.
this class is a functor for "for_each" algorithm
allocate(size_t sz)
constructor it fix the size
Parameters
howmany byte to shift

Definition at line 401 of file ExtPreAlloc.hpp.

◆ shift_forward()

template<typename Mem >
void ExtPreAlloc< Mem >::shift_forward ( size_t  sz)
inline

shift the pointer forward

The same as shift backward, but in this case it move the pointer forward

In general you use this function after the you went back with shift_backward and you have to move forward again

Warning
when you shift forward the pointer, the last allocation is lost this mean that you have to do again an allocation.

Definition at line 418 of file ExtPreAlloc.hpp.

◆ size()

template<typename Mem >
virtual size_t ExtPreAlloc< Mem >::size ( ) const
inlinevirtual

Get the size of the LAST allocated memory.

Get the size of the allocated memory

Returns
the size of the allocated memory

Implements memory.

Definition at line 319 of file ExtPreAlloc.hpp.

Field Documentation

◆ a_seq

template<typename Mem >
size_t ExtPreAlloc< Mem >::a_seq
private

Actual allocation pointer.

Definition at line 30 of file ExtPreAlloc.hpp.

◆ l_size

template<typename Mem >
size_t ExtPreAlloc< Mem >::l_size
private

Last allocation size.

Definition at line 33 of file ExtPreAlloc.hpp.

◆ mem

template<typename Mem >
Mem* ExtPreAlloc< Mem >::mem
private

Main class for memory allocation.

Definition at line 36 of file ExtPreAlloc.hpp.

◆ ref_cnt

template<typename Mem >
long int ExtPreAlloc< Mem >::ref_cnt
private

Reference counter.

Definition at line 39 of file ExtPreAlloc.hpp.


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