#include <dispenso/detail/math.h>
#include <dispenso/platform.h>
Go to the source code of this file.
A file providing SmallBufferAllocator. This allocator can allocate and deallocate chunks of a set size in a way that is efficient and scales quite well across many threads.
Definition in file small_buffer_allocator.h.
◆ allocSmallBuffer()
template<size_t kBlockSize>
char * dispenso::allocSmallBuffer |
( |
| ) |
|
|
inline |
Allocate a small buffer from a small buffer pool.
- Template Parameters
-
kBlockSize | The size of the block to allocate. Must be a power of two, and must be less than or equal to kMaxSmallBufferSize. |
- Returns
- The pointer to the allocated block of memory.
- Note
- : The returned buffer must be returned to the pool via deallocSmallBuffer templatized on the same block size. If kBlockSize > kMaxSmallBufferSize, this function falls back on alignedMalloc. If DISPENSO_NO_SMALL_BUFFER_ALLOCATOR is defined, we will always fall back on alignedMalloc/alignedFree.
Definition at line 87 of file small_buffer_allocator.h.
◆ approxBytesAllocatedSmallBuffer()
template<size_t kBlockSize>
size_t dispenso::approxBytesAllocatedSmallBuffer |
( |
| ) |
|
Get the approximate bytes allocated for a single small buffer pool (associated with kBlockSize). This function is not highly performant and locks, and should only be used for diagnostics (e.g. tests).
- Template Parameters
-
kBlockSize | The block size for the pool to query. |
Definition at line 112 of file small_buffer_allocator.h.
◆ deallocSmallBuffer()
template<size_t kBlockSize>
void dispenso::deallocSmallBuffer |
( |
void * |
buf | ) |
|
|
inline |
Free a small buffer from a small buffer pool.
- Template Parameters
-
kBlockSize | The size of the block to allocate. Must be a power of two, and must be less than or equal to kMaxSmallBufferSize. |
- Parameters
-
buf | the pointer to block of memory to return to the pool. Must have been allocated with allocSmallBuffer templatized on the same block size. |
- Note
- : If kBlockSize > kMaxSmallBufferSize, this function falls back on alignedFree.
Definition at line 100 of file small_buffer_allocator.h.
◆ kMaxSmallBufferSize
constexpr size_t dispenso::kMaxSmallBufferSize = 256 |
|
constexpr |
Set a standard for the maximum chunk size for use within dispenso. The reason for this limit is that there are diminishing returns after a certain size, and each new pool has it's own memory overhead.
Definition at line 26 of file small_buffer_allocator.h.