cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
cppcore::TScratchAllocator< T > Class Template Reference

A simple scratch allocator. More...

#include <TScratchAllocator.h>

Public Member Functions

 TScratchAllocator ()=default
 The default class constructor.
 TScratchAllocator (size_t numItems)
 The class constructor with the pool size.
 ~TScratchAllocator ()
 The class destructor.
T * alloc (size_t numItems)
 Will allocate the number of items.
void reserve (size_t size)
 Will reserve the pool.
void clear ()
 Will clear the pool, memory will be deallocated.
size_t capacity () const
 Returns the capacity of items in the pool allocator.
size_t reservedMem () const
 Will return the reserved memory in bytes.
size_t freeMem () const
 Will return the free memory in the pool in bytes.

Detailed Description

template<class T>
class cppcore::TScratchAllocator< T >

A simple scratch allocator.

You can use it to manage all the dynamic allocations without caring about cleaning it up. All Allocations will be a one-shot alloc, which do not need to get released. When calling clear all allocation will be invalidated and cannot be used anymore.

Definition at line 42 of file TScratchAllocator.h.

Constructor & Destructor Documentation

◆ TScratchAllocator() [1/2]

template<class T>
cppcore::TScratchAllocator< T >::TScratchAllocator ( )
default

The default class constructor.

◆ TScratchAllocator() [2/2]

template<class T>
cppcore::TScratchAllocator< T >::TScratchAllocator ( size_t numItems)
inlineexplicit

The class constructor with the pool size.

Parameters
[in]numItemsThe buffer size.

Definition at line 89 of file TScratchAllocator.h.

References reserve().

◆ ~TScratchAllocator()

template<class T>
cppcore::TScratchAllocator< T >::~TScratchAllocator ( )
inline

The class destructor.

Definition at line 94 of file TScratchAllocator.h.

References clear().

Member Function Documentation

◆ alloc()

template<class T>
T * cppcore::TScratchAllocator< T >::alloc ( size_t numItems)
inline

Will allocate the number of items.

Parameters
[in]numItemsThe number of items.
Returns
Pointr showing to the scratch buffer.

Definition at line 99 of file TScratchAllocator.h.

◆ capacity()

template<class T>
size_t cppcore::TScratchAllocator< T >::capacity ( ) const
inline

Returns the capacity of items in the pool allocator.

Returns
The capacity.

Definition at line 138 of file TScratchAllocator.h.

◆ clear()

template<class T>
void cppcore::TScratchAllocator< T >::clear ( )
inline

Will clear the pool, memory will be deallocated.

Note
All instances which are currently is use will get invalid. PLease use with care.

Definition at line 131 of file TScratchAllocator.h.

Referenced by reserve(), and ~TScratchAllocator().

◆ freeMem()

template<class T>
size_t cppcore::TScratchAllocator< T >::freeMem ( ) const
inline

Will return the free memory in the pool in bytes.

Returns
The free memory in bytes.

Definition at line 148 of file TScratchAllocator.h.

◆ reserve()

template<class T>
void cppcore::TScratchAllocator< T >::reserve ( size_t size)

Will reserve the pool.

@apram[in] size The pool size to reserve.

Definition at line 123 of file TScratchAllocator.h.

References clear().

Referenced by TScratchAllocator().

◆ reservedMem()

template<class T>
size_t cppcore::TScratchAllocator< T >::reservedMem ( ) const
inline

Will return the reserved memory in bytes.

Returns
The reserved memory in bytes.

Definition at line 143 of file TScratchAllocator.h.


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