LvArray
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
LvArray::MallocBuffer< T > Class Template Reference

Implements the Buffer interface using malloc and free. More...

#include <MallocBuffer.hpp>

Inheritance diagram for LvArray::MallocBuffer< T >:
Inheritance graph

Public Types

using value_type = T
 Alias used in the bufferManipulation functions.
 

Public Member Functions

LVARRAY_HOST_DEVICE constexpr MallocBuffer (bool=true)
 Constructor for creating an empty or uninitialized buffer. More...
 
 MallocBuffer (MallocBuffer const &)=default
 Copy constructor, creates a shallow copy.
 
 MallocBuffer (MallocBuffer const &src, std::ptrdiff_t)
 Sized copy constructor, creates a shallow copy. More...
 
LVARRAY_HOST_DEVICE constexpr MallocBuffer (MallocBuffer &&src)
 Move constructor, creates a shallow copy. More...
 
template<typename U >
LVARRAY_HOST_DEVICE constexpr MallocBuffer (MallocBuffer< U > const &src)
 Create a shallow copy of src but with a different type. More...
 
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR MallocBufferoperator= (MallocBuffer const &src)
 Copy assignment operator, creates a shallow copy. More...
 
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR MallocBufferoperator= (MallocBuffer &&src)
 Move assignment operator, creates a shallow copy. More...
 
LVARRAY_HOST_DEVICE void reallocate (std::ptrdiff_t const size, MemorySpace const space, std::ptrdiff_t const newCapacity)
 Reallocate the buffer to the new capacity. More...
 
LVARRAY_HOST_DEVICE void free ()
 Free the data in the buffer but does not destroy any values. More...
 
LVARRAY_HOST_DEVICE std::ptrdiff_t capacity () const
 
LVARRAY_HOST_DEVICE constexpr T * data () const
 
template<typename INDEX_TYPE >
LVARRAY_HOST_DEVICE constexpr T & operator[] (INDEX_TYPE const i) const
 
- Public Member Functions inherited from LvArray::bufferManipulation::VoidBuffer
void moveNested (MemorySpace const space, std::ptrdiff_t const size, bool const touch) const
 Move the buffer to the given execution space, optionally touching it. More...
 
void move (MemorySpace const space, bool const touch) const
 Move the buffer to the given execution space, optionally touching it. More...
 
MemorySpace getPreviousSpace () const
 
void registerTouch (MemorySpace const space) const
 Touch the buffer in the given space. More...
 
template<typename = VoidBuffer>
LVARRAY_HOST_DEVICE void setName (std::string const &name)
 Set the name associated with this buffer. More...
 

Static Public Attributes

static constexpr bool hasShallowCopy = true
 Signifies that the MallocBuffer's copy semantics are shallow.
 

Private Attributes

T *LVARRAY_RESTRICT m_data = nullptr
 A pointer to the data.
 
std::ptrdiff_t m_capacity = 0
 The size of the allocation.
 

Detailed Description

template<typename T>
class LvArray::MallocBuffer< T >

Implements the Buffer interface using malloc and free.

Template Parameters
Ttype of data that is contained in the buffer.

Both the copy constructor and copy assignment constructor perform a shallow copy of the source. Similarly the destructor does not free the allocation.

Note
The parent class bufferManipulation::VoidBuffer provides the default execution space related methods.

Constructor & Destructor Documentation

◆ MallocBuffer() [1/4]

template<typename T>
LVARRAY_HOST_DEVICE constexpr LvArray::MallocBuffer< T >::MallocBuffer ( bool  = true)
inline

Constructor for creating an empty or uninitialized buffer.

Note
An uninitialized MallocBuffer is equivalent to an empty MallocBuffer and does not need to be free'd.

◆ MallocBuffer() [2/4]

template<typename T>
LvArray::MallocBuffer< T >::MallocBuffer ( MallocBuffer< T > const &  src,
std::ptrdiff_t   
)
inline

Sized copy constructor, creates a shallow copy.

Parameters
srcThe buffer to be coppied.

◆ MallocBuffer() [3/4]

template<typename T>
LVARRAY_HOST_DEVICE constexpr LvArray::MallocBuffer< T >::MallocBuffer ( MallocBuffer< T > &&  src)
inline

Move constructor, creates a shallow copy.

Parameters
srcThe buffer to be moved from, is empty after the move.

◆ MallocBuffer() [4/4]

template<typename T>
template<typename U >
LVARRAY_HOST_DEVICE constexpr LvArray::MallocBuffer< T >::MallocBuffer ( MallocBuffer< U > const &  src)
inline

Create a shallow copy of src but with a different type.

Template Parameters
UThe type to convert from.
Parameters
srcThe buffer to copy.

Member Function Documentation

◆ capacity()

template<typename T>
LVARRAY_HOST_DEVICE std::ptrdiff_t LvArray::MallocBuffer< T >::capacity ( ) const
inline
Returns
Return the capacity of the buffer.

◆ data()

template<typename T>
LVARRAY_HOST_DEVICE constexpr T* LvArray::MallocBuffer< T >::data ( ) const
inline
Returns
Return a pointer to the beginning of the buffer.

◆ free()

template<typename T>
LVARRAY_HOST_DEVICE void LvArray::MallocBuffer< T >::free ( )
inline

Free the data in the buffer but does not destroy any values.

Note
To destroy the values and free the data call bufferManipulation::free.

◆ operator=() [1/2]

template<typename T>
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR MallocBuffer& LvArray::MallocBuffer< T >::operator= ( MallocBuffer< T > const &  src)
inline

Copy assignment operator, creates a shallow copy.

Parameters
srcThe buffer to be copied.
Returns
*this.

◆ operator=() [2/2]

template<typename T>
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR MallocBuffer& LvArray::MallocBuffer< T >::operator= ( MallocBuffer< T > &&  src)
inline

Move assignment operator, creates a shallow copy.

Parameters
srcThe buffer to be moved from, is empty after the move.
Returns
*this.

◆ operator[]()

template<typename T>
template<typename INDEX_TYPE >
LVARRAY_HOST_DEVICE constexpr T& LvArray::MallocBuffer< T >::operator[] ( INDEX_TYPE const  i) const
inline
Template Parameters
INDEX_TYPEthe type used to index into the values.
Returns
The value at position i .
Parameters
iThe position of the value to access.
Note
No bounds checks are performed.

◆ reallocate()

template<typename T>
LVARRAY_HOST_DEVICE void LvArray::MallocBuffer< T >::reallocate ( std::ptrdiff_t const  size,
MemorySpace const  space,
std::ptrdiff_t const  newCapacity 
)
inline

Reallocate the buffer to the new capacity.

Parameters
sizeThe number of values that are initialized in the buffer.
spaceThe space to perform the reallocation in, not used.
newCapacityThe new capacity of the buffer.

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