16#include <dispenso/detail/math.h>
17#include <dispenso/platform.h>
30DISPENSO_DLL_ACCESS
char* allocSmallBufferImpl(
size_t ordinal);
31DISPENSO_DLL_ACCESS
void deallocSmallBufferImpl(
size_t ordinal,
void* buf);
33DISPENSO_DLL_ACCESS
size_t approxBytesAllocatedSmallBufferImpl(
size_t ordinal);
41constexpr size_t getOrdinal(
size_t blockSize) {
42 return std::max<ssize_t>(0, log2const(blockSize) - 2);
45template <
size_t kBlockSize>
46inline std::enable_if_t<(kBlockSize <= kMaxSmallBufferSize), char*> allocSmallOrLarge() {
47#if defined(DISPENSO_NO_SMALL_BUFFER_ALLOCATOR)
48 return reinterpret_cast<char*
>(alignedMalloc(kBlockSize, kBlockSize));
50 return allocSmallBufferImpl(getOrdinal(kBlockSize));
54template <
size_t kBlockSize>
56 return reinterpret_cast<char*
>(alignedMalloc(kBlockSize, kBlockSize));
59template <
size_t kBlockSize>
60inline std::enable_if_t<(kBlockSize <= kMaxSmallBufferSize), void> deallocSmallOrLarge(
void* buf) {
61#if defined(DISPENSO_NO_SMALL_BUFFER_ALLOCATOR)
64 deallocSmallBufferImpl(getOrdinal(kBlockSize), buf);
68template <
size_t kBlockSize>
69inline std::enable_if_t<(kBlockSize >
kMaxSmallBufferSize),
void> deallocSmallOrLarge(
void* buf) {
86template <
size_t kBlockSize>
88 return detail::allocSmallOrLarge<kBlockSize>();
99template <
size_t kBlockSize>
101 detail::deallocSmallOrLarge<kBlockSize>(buf);
111template <
size_t kBlockSize>
113 return detail::approxBytesAllocatedSmallBufferImpl(detail::getOrdinal(kBlockSize));
void deallocSmallBuffer(void *buf)
constexpr size_t kMaxSmallBufferSize
char * allocSmallBuffer()
size_t approxBytesAllocatedSmallBuffer()