86 static std::byte * take( std::size_t b , std::size_t & got ,
87 std::size_t a = __STDCPP_DEFAULT_NEW_ALIGNMENT__ ) {
88 if( a > __STDCPP_DEFAULT_NEW_ALIGNMENT__ )
91 std::lock_guard< std::mutex > g( slot().lock );
92 if( slot().p && ( slot().size >= b ) ) {
94 return( std::exchange( slot().p ,
nullptr ) );
98 return( HugePageAllocator< std::byte >().allocate( b ) );
102 static void give( std::byte * p , std::size_t b ) {
103 std::byte * drop = p;
106 std::lock_guard< std::mutex > g( slot().lock );
107 if( ! slot().p || ( slot().size < b ) ) {
108 std::swap( drop , slot().p );
109 std::swap( db , slot().size );
113 HugePageAllocator< std::byte >().deallocate( drop , db );
120 std::byte * p =
nullptr;
121 std::size_t size = 0;
124 HugePageAllocator< std::byte >().deallocate( p , size );
128 static Slot & slot(
void ) {
140 explicit ScratchBuffer( std::size_t n )
141 : f_p( reinterpret_cast< T * >(
142 ScratchRoom::take( std::max< std::size_t >( n , 1 ) * sizeof( T ) ,
144 alignof( T ) ) ) ) { }
147 ScratchRoom::give(
reinterpret_cast< std::byte *
>( f_p ) , f_b );
149 ScratchBuffer(
const ScratchBuffer & ) =
delete;
150 ScratchBuffer & operator=(
const ScratchBuffer & ) =
delete;
152 [[nodiscard]] T * data(
void )
const {
return( f_p ); }
An allocator for the large blocks of a structure, beyond the book: a request of at least one huge pag...
static constexpr std::size_t PAGE
the size of a huge page, in bytes
Definition HugePageAllocator.h:177