cuLite v0.3.1
A lite CUDA C++ Interface
Loading...
Searching...
No Matches
culite::PinnedBufferVoid Class Reference

A RAII wrapper for untyped pinned host memory allocation. More...

Public Member Functions

 PinnedBufferVoid ()
 Default constructor.
 PinnedBufferVoid (std::size_t n)
 Constructs a pinned buffer with specified capacity.
 ~PinnedBufferVoid ()
 Destructor.
void reserve (std::size_t n)
 Reserves pinned memory for at least the specified number of bytes.
void clear () noexcept
 Frees the allocated pinned memory.
void * data () noexcept
 Returns a pointer to the pinned memory buffer.
const void * data () const noexcept
 Returns a const pointer to the pinned memory buffer.
std::size_t size () const noexcept
 Returns the number of bytes in the buffer.

Detailed Description

A RAII wrapper for untyped pinned host memory allocation.

This class manages a dynamically allocated buffer of raw bytes in pinned host memory. It automatically handles memory allocation and deallocation following RAII principles, ensuring that pinned memory is properly freed when the buffer goes out of scope. Unlike PinnedBuffer, this class manages untyped memory (void*).

Constructor & Destructor Documentation

◆ PinnedBufferVoid() [1/2]

culite::PinnedBufferVoid::PinnedBufferVoid ( )
inline

Default constructor.

Constructs an empty pinned buffer with no allocated memory.

◆ PinnedBufferVoid() [2/2]

culite::PinnedBufferVoid::PinnedBufferVoid ( std::size_t n)
inlineexplicit

Constructs a pinned buffer with specified capacity.

Constructs a pinned buffer and reserves memory for n bytes on the host.

Parameters
[in]nThe number of bytes to allocate.

◆ ~PinnedBufferVoid()

culite::PinnedBufferVoid::~PinnedBufferVoid ( )
inline

Destructor.

Automatically frees the allocated pinned memory.

Member Function Documentation

◆ reserve()

void culite::PinnedBufferVoid::reserve ( std::size_t n)
inline

Reserves pinned memory for at least the specified number of bytes.

If n is greater than the current size, the existing memory is freed and new memory is allocated. If the allocation fails, the buffer is left empty.

Parameters
[in]nThe number of bytes to reserve.

◆ clear()

void culite::PinnedBufferVoid::clear ( )
inlinenoexcept

Frees the allocated pinned memory.

Releases all pinned memory and resets the buffer to an empty state.

Note
This function is marked noexcept and is guaranteed not to throw exceptions.

◆ data() [1/2]

void * culite::PinnedBufferVoid::data ( )
inlinenoexcept

Returns a pointer to the pinned memory buffer.

Provides direct access to the underlying untyped pinned memory.

Returns
A pointer to the pinned buffer.

◆ data() [2/2]

const void * culite::PinnedBufferVoid::data ( ) const
inlinenoexcept

Returns a const pointer to the pinned memory buffer.

Provides direct read-only access to the underlying untyped pinned memory.

Returns
A const pointer to the pinned buffer.

◆ size()

std::size_t culite::PinnedBufferVoid::size ( ) const
inlinenoexcept

Returns the number of bytes in the buffer.

Returns the capacity of the buffer (number of bytes allocated).

Returns
The number of bytes the buffer can hold.