Thread-safe singleton pool for reusable bounce buffers. More...
#include <bounce_buffer.hpp>
Classes | |
| class | Buffer |
| RAII wrapper for a host bounce buffer allocation. More... | |
Public Member Functions | |
| Buffer | get () |
| Acquire a bounce buffer from the pool. More... | |
| void | put (void *buffer, std::size_t size) |
| Return a buffer to the pool for reuse. More... | |
| std::size_t | clear () |
| Free all retained allocations in the pool. More... | |
| BounceBufferPool (BounceBufferPool const &)=delete | |
| BounceBufferPool & | operator= (BounceBufferPool const &)=delete |
| BounceBufferPool (BounceBufferPool &&o)=delete | |
| BounceBufferPool & | operator= (BounceBufferPool &&o)=delete |
Static Public Member Functions | |
| static KVIKIO_EXPORT BounceBufferPool & | instance () |
| Get the singleton instance of the pool. More... | |
Thread-safe singleton pool for reusable bounce buffers.
Manages a pool of host memory buffers used for staging data during I/O operations. Buffers are retained and reused across calls to minimize allocation overhead. The pool uses a LIFO (stack) allocation strategy optimized for cache locality.
All buffers in the pool have the same size, controlled by defaults::bounce_buffer_size(). If the buffer size changes, all cached buffers are cleared and reallocated at the new size.
Call BounceBufferPool::get to get an allocation that will be retained when it goes out of scope (RAII). The size of all retained allocations are the same.
| Allocator | The allocator policy that determines buffer properties:
|
Definition at line 118 of file bounce_buffer.hpp.
| std::size_t kvikio::BounceBufferPool< Allocator >::clear | ( | ) |
Free all retained allocations in the pool.
Clears the pool and deallocates all cached buffers. Useful for reclaiming memory when bounce buffers are no longer needed.
| Buffer kvikio::BounceBufferPool< Allocator >::get | ( | ) |
Acquire a bounce buffer from the pool.
Returns a cached buffer if available, otherwise allocates a new one. The returned Buffer object will automatically return the buffer to the pool when it goes out of scope.
| CudaError | if allocation fails (e.g., invalid CUDA context for pinned allocators) |
|
static |
Get the singleton instance of the pool.
Each template instantiation (different Allocator) has its own singleton instance.
| void kvikio::BounceBufferPool< Allocator >::put | ( | void * | buffer, |
| std::size_t | size | ||
| ) |
Return a buffer to the pool for reuse.
Typically called automatically by Buffer's destructor. Only adds the buffer to the pool if its size matches the current pool buffer size; otherwise the buffer is deallocated immediately.
| buffer | Pointer to memory to return |
| size | Size of the buffer in bytes |