memory
Typedefs | Member Functions | Related Functions
temporary_stack Class Reference

Detailed Description

A wrapper around the memory_stack that is used by the temporary_allocator.

There should be at least one per-thread.

Typedefs

using growth_tracker = detail::temporary_block_allocator::growth_tracker
 The type of the handler called when the internal memory_stack grows.
 

Member Functions

growth_tracker set_growth_tracker (growth_tracker t) noexcept
 
growth_tracker get_growth_tracker () noexcept
 
 temporary_stack (std::size_t initial_size)
 
std::size_t next_capacity () const noexcept
 

Related Functions

temporary_stackget_temporary_stack (std::size_t initial_size=temporary_stack_initializer::default_stack_size)
 

Typedefs

◆ growth_tracker

using growth_tracker = detail::temporary_block_allocator::growth_tracker

The type of the handler called when the internal memory_stack grows.

It gets the size of the new block that will be allocated.

Required Behavior:
The handler shall log the growth, throw an exception or aborts the program. If this function does not return, the growth is prevented but the allocator unusable until memory is freed.
Default Behavior:
The default handler does nothing.

Constructors

◆ temporary_stack()

temporary_stack ( std::size_t  initial_size)
explicit
Effects:
Creates it with a given initial size of the stack. It can grow if needed, although that is expensive.
Requires:
initial_size must be greater than 0.

Member Functions

◆ set_growth_tracker()

growth_tracker set_growth_tracker ( growth_tracker  t)
noexcept
Effects:
Sets h as the new growth_tracker. A nullptr sets the default growth_tracker. Each thread has its own, separate tracker.
Returns:
The previous growth_tracker. This is never nullptr.

◆ get_growth_tracker()

growth_tracker get_growth_tracker ( )
noexcept
Returns:
The current growth_tracker. This is never nullptr.

◆ next_capacity()

std::size_t next_capacity ( ) const
noexcept
Returns:
next_capacity() of the internal memory_stack.

Related Functions

◆ get_temporary_stack()

temporary_stack & get_temporary_stack ( std::size_t  initial_size = temporary_stack_initializer::default_stack_size)
related
Effects:
Creates the per-thread temporary_stack with the given initial size, if it wasn't already created.
Returns:
The per-thread temporary_stack.
Requires:
There must be a per-thread temporary stack (FOONATHAN_MEMORY_TEMPORARY_STACK_MODE must not be equal to 0).
Note
If FOONATHAN_MEMORY_TEMPORARY_STACK_MODE is equal to 1, this function can create the temporary stack. But if there is no temporary_stack_initializer, it won't be destroyed.