ROSE 0.11.145.147
Public Types | Public Member Functions | List of all members
Sawyer::StackAllocator< T > Class Template Reference

Description

template<typename T>
class Sawyer::StackAllocator< T >

Stack-like allocator.

This allocator allocates single elements of POD type from a stack-like pool. The allocator is intentionally not thread safe and is intended to be used in multi-threaded applications where each thread is allocating and freeing elements in a stack-like order from its own allocator.

Definition at line 21 of file StackAllocator.h.

#include <Sawyer/StackAllocator.h>

Inheritance diagram for Sawyer::StackAllocator< T >:
Inheritance graph
[legend]

Public Types

typedef T Value
 Type of values being allocated.
 

Public Member Functions

 StackAllocator (size_t elmtsPerBlock)
 
void prune ()
 Free unused large blocks.
 
T * reserve (size_t nElmts)
 Reserve space for objects.
 
T * allocNext ()
 Allocate one element.
 
void revert (T *ptr)
 Free all elements back to the specified element.
 

Member Typedef Documentation

◆ Value

template<typename T >
typedef T Sawyer::StackAllocator< T >::Value

Type of values being allocated.

Definition at line 23 of file StackAllocator.h.

Constructor & Destructor Documentation

◆ StackAllocator()

template<typename T >
Sawyer::StackAllocator< T >::StackAllocator ( size_t  elmtsPerBlock)
inlineexplicit

Definition at line 32 of file StackAllocator.h.

◆ ~StackAllocator()

template<typename T >
Sawyer::StackAllocator< T >::~StackAllocator ( )
inline

Definition at line 35 of file StackAllocator.h.

Member Function Documentation

◆ prune()

template<typename T >
void Sawyer::StackAllocator< T >::prune ( )
inline

Free unused large blocks.

Definition at line 44 of file StackAllocator.h.

◆ reserve()

template<typename T >
T * Sawyer::StackAllocator< T >::reserve ( size_t  nElmts)
inline

Reserve space for objects.

Reserves space for nElmts elements of type T and returns a pointer to the first one. Although this reserves space for objects, the memory is not yet usable to store an object. The next allocation request will give back the same address as returned here, unless the allocated is reverted to an earlier address in the mean time.

Definition at line 54 of file StackAllocator.h.

◆ allocNext()

template<typename T >
T * Sawyer::StackAllocator< T >::allocNext ( )
inline

Allocate one element.

If this allocation is below the amount previously reserved then it is guaranteed to be adjacent to the previous allocation.

Definition at line 64 of file StackAllocator.h.

◆ revert()

template<typename T >
void Sawyer::StackAllocator< T >::revert ( T *  ptr)
inline

Free all elements back to the specified element.

Reverts the state of this allocator so that the specified ptr would be the return value from allocNext. If this results in whole large blocks becoming unused they are not returned to the system (call prune if that's desired).

Definition at line 73 of file StackAllocator.h.


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