NumericAL
A header-only C++20 lexer built on REAL
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | List of all members
numerical::detail::kept_blocks< Alignment, Places, Largest > Class Template Reference

Blocks freed and kept for the next buffer that fits one: a fresh block's pages are each faulted in and zeroed by the system at their first write, on the thread that writes it (glibc hands a large freed block back to the system unless the next request is of its very size; macOS's allocator likewise), where a kept block's are already in place. Places blocks at most, each under Largest bytes, the newest kept: a block freed while every place is taken frees the one kept longest. The first allocation one fits, with no more than half of it unused, takes it. Blocks aligned on Alignment. More...

#include <buffer.hpp>

Classes

struct  block
 

Public Member Functions

 kept_blocks ()=default
 
 ~kept_blocks ()
 Frees the blocks still kept.
 
 kept_blocks (const kept_blocks &)=delete
 
kept_blocks & operator= (const kept_blocks &)=delete
 
 kept_blocks (kept_blocks &&)=delete
 
kept_blocks & operator= (kept_blocks &&)=delete
 
std::byte * take (std::size_t bytes, std::size_t &got) noexcept
 A kept block of at least bytes and under twice as many, its size in got; nullptr if none.
 
bool keep (std::byte *start, std::size_t bytes) noexcept
 Keeps the block at start of bytes if it is under largest, in place of the block kept longest when every place is taken (that one freed): the blocks of the sizes in use stay, those of a size no longer asked for leave. False, the block not kept, if it is too large.
 
void clear () noexcept
 Frees every block kept (numerical::release_memory).
 

Static Public Member Functions

static kept_blocks & shared ()
 The process's blocks, never destroyed: a buffer of static storage may be freed after any destructor.
 

Static Public Attributes

static constexpr std::size_t alignment {Alignment}
 The alignment of a block.
 
static constexpr std::size_t largest {Largest}
 The bytes from which a freed block is freed at once, not kept.
 

Private Attributes

std::mutex lock_
 
std::array< block, Places > kept_ {}
 
std::size_t kept_count_ {0}
 

Detailed Description

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
class numerical::detail::kept_blocks< Alignment, Places, Largest >

Blocks freed and kept for the next buffer that fits one: a fresh block's pages are each faulted in and zeroed by the system at their first write, on the thread that writes it (glibc hands a large freed block back to the system unless the next request is of its very size; macOS's allocator likewise), where a kept block's are already in place. Places blocks at most, each under Largest bytes, the newest kept: a block freed while every place is taken frees the one kept longest. The first allocation one fits, with no more than half of it unused, takes it. Blocks aligned on Alignment.

Definition at line 96 of file buffer.hpp.

Constructor & Destructor Documentation

◆ kept_blocks() [1/3]

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
numerical::detail::kept_blocks< Alignment, Places, Largest >::kept_blocks ( )
default

◆ ~kept_blocks()

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
numerical::detail::kept_blocks< Alignment, Places, Largest >::~kept_blocks ( )
inline

Frees the blocks still kept.

Definition at line 116 of file buffer.hpp.

◆ kept_blocks() [2/3]

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
numerical::detail::kept_blocks< Alignment, Places, Largest >::kept_blocks ( const kept_blocks< Alignment, Places, Largest > &  )
delete

◆ kept_blocks() [3/3]

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
numerical::detail::kept_blocks< Alignment, Places, Largest >::kept_blocks ( kept_blocks< Alignment, Places, Largest > &&  )
delete

Member Function Documentation

◆ clear()

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
void numerical::detail::kept_blocks< Alignment, Places, Largest >::clear ( )
inlinenoexcept

Frees every block kept (numerical::release_memory).

Definition at line 182 of file buffer.hpp.

◆ keep()

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
bool numerical::detail::kept_blocks< Alignment, Places, Largest >::keep ( std::byte *  start,
std::size_t  bytes 
)
inlinenoexcept

Keeps the block at start of bytes if it is under largest, in place of the block kept longest when every place is taken (that one freed): the blocks of the sizes in use stay, those of a size no longer asked for leave. False, the block not kept, if it is too large.

Definition at line 153 of file buffer.hpp.

◆ operator=() [1/2]

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
kept_blocks & numerical::detail::kept_blocks< Alignment, Places, Largest >::operator= ( const kept_blocks< Alignment, Places, Largest > &  )
delete

◆ operator=() [2/2]

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
kept_blocks & numerical::detail::kept_blocks< Alignment, Places, Largest >::operator= ( kept_blocks< Alignment, Places, Largest > &&  )
delete

◆ shared()

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
static kept_blocks & numerical::detail::kept_blocks< Alignment, Places, Largest >::shared ( )
inlinestatic

The process's blocks, never destroyed: a buffer of static storage may be freed after any destructor.

Definition at line 107 of file buffer.hpp.

◆ take()

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
std::byte * numerical::detail::kept_blocks< Alignment, Places, Largest >::take ( std::size_t  bytes,
std::size_t &  got 
)
inlinenoexcept

A kept block of at least bytes and under twice as many, its size in got; nullptr if none.

Definition at line 131 of file buffer.hpp.

Member Data Documentation

◆ alignment

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
constexpr std::size_t numerical::detail::kept_blocks< Alignment, Places, Largest >::alignment {Alignment}
staticconstexpr

The alignment of a block.

Definition at line 101 of file buffer.hpp.

◆ kept_

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
std::array<block, Places> numerical::detail::kept_blocks< Alignment, Places, Largest >::kept_ {}
private

Definition at line 206 of file buffer.hpp.

◆ kept_count_

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
std::size_t numerical::detail::kept_blocks< Alignment, Places, Largest >::kept_count_ {0}
private

Definition at line 207 of file buffer.hpp.

◆ largest

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
constexpr std::size_t numerical::detail::kept_blocks< Alignment, Places, Largest >::largest {Largest}
staticconstexpr

The bytes from which a freed block is freed at once, not kept.

Definition at line 104 of file buffer.hpp.

◆ lock_

template<std::size_t Alignment, std::size_t Places, std::size_t Largest>
std::mutex numerical::detail::kept_blocks< Alignment, Places, Largest >::lock_
private

Definition at line 205 of file buffer.hpp.


The documentation for this class was generated from the following file: