ROSE  0.11.145.0
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 <util/Sawyer/StackAllocator.h>

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

Public Types

typedef T Value
 Type of values being allocated. More...
 

Public Member Functions

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

Member Typedef Documentation

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

Type of values being allocated.

Definition at line 23 of file StackAllocator.h.

Member Function Documentation

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

Free unused large blocks.

Definition at line 44 of file StackAllocator.h.

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.

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.

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: