WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::temporary_stack_initializer Class Reference

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

#include <wpi/memory/temporary_allocator.hpp>

Classes

struct  defer_create_t
 

Public 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
 

Static Public Attributes

static constexpr std::size_t default_stack_size = 4096u
 
static const struct wpi::memory::temporary_stack_initializer::defer_create_t defer_create
 

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 WPI_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 WPI_MEMORY_TEMPORARY_STACK_MODE == 0, the use of this class has no effect, because the per-thread stack is disabled.

Constructor & Destructor Documentation

◆ temporary_stack_initializer() [1/3]

wpi::memory::temporary_stack_initializer::temporary_stack_initializer ( defer_create_t )
inlinenoexcept
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 WPI_MEMORY_TEMPORARY_STACK_MODE == 0, this function has no effect.

◆ temporary_stack_initializer() [2/3]

wpi::memory::temporary_stack_initializer::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 WPI_MEMORY_TEMPORARY_STACK_MODE != 0.
Note
If WPI_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()

wpi::memory::temporary_stack_initializer::~temporary_stack_initializer ( )
noexcept
Effects:
Destroys the per-thread stack if it isn't already destroyed.

◆ temporary_stack_initializer() [3/3]

wpi::memory::temporary_stack_initializer::temporary_stack_initializer ( temporary_stack_initializer && )
delete

Member Function Documentation

◆ operator=()

temporary_stack_initializer & wpi::memory::temporary_stack_initializer::operator= ( temporary_stack_initializer && )
delete

Member Data Documentation

◆ default_stack_size

std::size_t wpi::memory::temporary_stack_initializer::default_stack_size = 4096u
staticconstexpr

◆ defer_create

const struct wpi::memory::temporary_stack_initializer::defer_create_t wpi::memory::temporary_stack_initializer::defer_create
static

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