CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
cookmem::TLSContextScope< Context, Tag > Class Template Reference

#include <allocator.h>

Public Member Functions

 TLSContextScope ()
 
 TLSContextScope (bool shareArena)
 
 TLSContextScope (const TLSContextScope &)=delete
 
TLSContextScope & operator= (const TLSContextScope &)=delete
 
Context & getContext ()
 

Detailed Description

template<class Context, class Tag>
class cookmem::TLSContextScope< Context, Tag >

Temporarily provides a function-scope context to default-constructed allocators using the matching TLSContextProvider.

Declare the scope before containers that use the context so those containers are destroyed before the context.

Constructor & Destructor Documentation

◆ TLSContextScope() [1/2]

template<class Context , class Tag >
cookmem::TLSContextScope< Context, Tag >::TLSContextScope ( )
inline

Constructor. Creates a new context with its own arena and makes it the active context of the current thread until the scope ends.

◆ TLSContextScope() [2/2]

template<class Context , class Tag >
cookmem::TLSContextScope< Context, Tag >::TLSContextScope ( bool  shareArena)
inlineexplicit

Constructor. Creates a new context based on the persistent thread-local context and makes it the active context of the current thread until the scope ends.

Parameters
shareArenatrue to share the arena of the persistent thread-local context. With CachedMemContext, segments freed by either context can then be reused by the other. false to give the new context its own arena.

Member Function Documentation

◆ getContext()

template<class Context , class Tag >
Context & cookmem::TLSContextScope< Context, Tag >::getContext ( )
inline

Get the memory context of this scope.

Returns
the context that is active while this scope exists.

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