All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions | List of all members
ucxx::HostBuffer Class Reference

A simple object containing a host buffer. More...

#include <buffer.h>

Inheritance diagram for ucxx::HostBuffer:
ucxx::Buffer

Public Member Functions

 HostBuffer (const HostBuffer &)=delete
 
HostBufferoperator= (HostBuffer const &)=delete
 
 HostBuffer (HostBuffer &&o)=delete
 
HostBufferoperator= (HostBuffer &&o)=delete
 
 HostBuffer (const size_t size)
 Constructor of concrete type HostBuffer. More...
 
 ~HostBuffer ()
 Destructor of concrete type HostBuffer. More...
 
void * release ()
 Release the allocated host buffer to the caller. More...
 
virtual void * data ()
 Get a pointer to the allocated raw host buffer. More...
 
- Public Member Functions inherited from ucxx::Buffer
 Buffer (const Buffer &)=delete
 
Bufferoperator= (Buffer const &)=delete
 
 Buffer (Buffer &&o)=delete
 
Bufferoperator= (Buffer &&o)=delete
 
virtual ~Buffer ()
 Virtual destructor. More...
 
BufferType getType () const noexcept
 Get the type of buffer the object holds. More...
 
size_t getSize () const noexcept
 Get the size of the contained buffer. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ucxx::Buffer
 Buffer (const BufferType bufferType, const size_t size)
 Protected constructor of abstract type Buffer. More...
 
- Protected Attributes inherited from ucxx::Buffer
BufferType _bufferType {BufferType::Invalid}
 Buffer type.
 
size_t _size
 Buffer size.
 

Detailed Description

A simple object containing a host buffer.

A buffer encapsulating a host buffer with its properties.

Constructor & Destructor Documentation

◆ HostBuffer()

ucxx::HostBuffer::HostBuffer ( const size_t  size)
explicit

Constructor of concrete type HostBuffer.

Constructor to materialize a buffer holding host memory. The internal buffer is allocated using malloc, and thus should be freed with free.

Parameters
[in]sizethe size of the host buffer to allocate.
// Allocate host buffer of 1KiB
auto buffer = HostBuffer(1024);

◆ ~HostBuffer()

ucxx::HostBuffer::~HostBuffer ( )

Destructor of concrete type HostBuffer.

Frees the underlying buffer, unless the underlying buffer was released to the user after a call to release.

Member Function Documentation

◆ data()

virtual void* ucxx::HostBuffer::data ( )
virtual

Get a pointer to the allocated raw host buffer.

Get a pointer to the underlying buffer, but does not release ownership.

// Allocate host buffer of 1KiB
auto buffer = HostBuffer(1024);
void* bufferPtr = buffer.data();
// do work on bufferPtr
// Memory is freed once `buffer` goes out-of-scope.
Exceptions
std::runtime_errorif object has been released.
Returns
the void pointer to the buffer.

Implements ucxx::Buffer.

◆ release()

void* ucxx::HostBuffer::release ( )

Release the allocated host buffer to the caller.

Release ownership of the buffer to the caller. After this method is called, the caller becomes responsible for its deallocation once it is not needed anymore. The buffer is allocated with malloc, and should be properly disposed of by a call to free.

The original HostBuffer object becomes invalid.

// Allocate host buffer of 1KiB
auto buffer = HostBuffer(1024);
void* bufferPtr = buffer.release();
// do work on bufferPtr
// Free buffer
free(bufferPtr);
Exceptions
std::runtime_errorif object has been released.
Returns
the void pointer to the buffer.

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