Documentation of memory

( foonathan/memory)

temporary_stack_initializer Class Reference

Detailed Description

Manually takes care of the lifetime of the per-thread temporary_stack.

The constructor will create it, if not already done, and the destructor will destroy it, if not already done.

Note
If there are multiple objects in a thread, this will lead to unnecessary construction and destruction of the stack. It is thus adviced to create one object on the top-level function of the thread, e.g. in main().
If FOONATHAN_MEMORY_TEMPORARY_STACK_MODE == 2, it is not necessary to use this class, the nifty counter will clean everything upon program termination. But it can still be used as an optimization if you have a thread that is terminated long before program exit. The automatic clean up will only occur much later.
If FOONATHAN_MEMORY_TEMPORARY_STACK_MODE == 0, the use of this class has no effect, because the per-thread stack is disabled.

Constants

static constexpr std::size_t default_stack_size
 
static const struct foonathan::memory::temporary_stack_initializer::defer_create_t defer_create
 

Member Functions

 temporary_stack_initializer (defer_create_t) noexcept
 
 temporary_stack_initializer (std::size_t initial_size=default_stack_size)
 
 ~temporary_stack_initializer () noexcept
 
 temporary_stack_initializer (temporary_stack_initializer &&)=delete
 
temporary_stack_initializeroperator= (temporary_stack_initializer &&)=delete
 

Constructors

§ temporary_stack_initializer() [1/2]

temporary_stack_initializer ( defer_create_t  )
noexcept
Effects:
Does not create the per-thread stack. It will be created by the first call to get_temporary_stack() in the current thread.
Note
If FOONATHAN_MEMORY_TEMPORARY_STACK_MODE == 0, this function has no effect.

§ temporary_stack_initializer() [2/2]

temporary_stack_initializer ( std::size_t  initial_size = default_stack_size)
Effects:
Creates the per-thread stack with the given default size if it wasn't already created.
Requires:
initial_size must not be 0 if FOONATHAN_MEMORY_TEMPORARY_STACK_MODE != 0.
Note
If FOONATHAN_MEMORY_TEMPORARY_STACK_MODE == 0, this function will issue a warning in debug mode. This can be disabled by passing 0 as the initial size.

§ ~temporary_stack_initializer()

Effects:
Destroys the per-thread stack if it isn't already destroyed.