Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cTempPool Class Reference

#include <cTempPool.h>

Public Member Functions

 cTempPool ()
 
virtual ~cTempPool ()
 
void CleanTemps ()
 
void * GetTempV (size_t nLenNeed)
 
void * GetTempV (size_t nLenNeed, const void *pData)
 
template<typename TYPE >
TYPEGetTempT (StrLen_t nLenNeed)
 
template<typename TYPE >
TYPEGetTempT (StrLen_t nLenNeed, const TYPE *pData)
 

Static Public Member Functions

static cTempPool *__stdcall GetTempPool ()
 
static void __stdcall FreeTempsForThreadManually ()
 
static void *__stdcall GetTempSV (size_t nLenNeed, const void *pData)
 
template<typename TYPE >
static TYPE *__stdcall GetTempST (StrLen_t nLenNeed)
 
template<typename TYPE >
static TYPE *__stdcall GetTempST (StrLen_t nLenNeed, const TYPE *pData)
 

Public Attributes

int m_iCountCur
 rotate this count to re-use buffers in m_aBlocks. More...
 
cArrayStruct< cHeapBlockm_aBlocks
 Temporary blocks to be used on a single thread. More...
 

Static Public Attributes

static const int k_iCountMax = 16
 Assume nested functions won't use more than m_aBlocks in a single thread. (e.g. This is the max number of args on a single sprintf) More...
 
static IThreadLocalsm_pThreadLocal = &cTempPool::sm_ThreadLocalDefault
 Allow this to be overloaded with a version that destructs on thread close. More...
 
static cThreadLocalSysNew< cTempPoolsm_ThreadLocalDefault
 

Detailed Description

A set of thread safe temporary strings/spaces for function arguments and Unicode/UTF8 conversions. Used by StrArg<>. Pool of re-used strings/spaces after k_iCountMax uses. use a new set for each thread. Thread Local/Safe.

Note
This is a bit of a hack as it assumes the strings are not in use when the rollover occurs ! beware of using more than k_iCountMax strings on one line. We can never be sure we are not re-using strings before they are ready. Just use cString is you want to always be safe?

Constructor & Destructor Documentation

◆ cTempPool()

Gray::cTempPool::cTempPool ( )
inline

◆ ~cTempPool()

virtual Gray::cTempPool::~cTempPool ( )
inlinevirtual

Member Function Documentation

◆ CleanTemps()

void Gray::cTempPool::CleanTemps ( )

reset contents for this pool. release element allocated memory. keep array.

◆ FreeTempsForThreadManually()

void GRAYCALL Gray::cTempPool::FreeTempsForThreadManually ( )
static

◆ GetTempPool()

cTempPool *GRAYCALL Gray::cTempPool::GetTempPool ( )
static

Get thread local cTempPool. create it if its not already allocated.

◆ GetTempST() [1/2]

template<typename TYPE >
static TYPE* __stdcall Gray::cTempPool::GetTempST ( StrLen_t  nLenNeed)
inlinestatic

Get thread local temp space.

  • nLenNeed = will add a space for '\0'

◆ GetTempST() [2/2]

template<typename TYPE >
static TYPE* __stdcall Gray::cTempPool::GetTempST ( StrLen_t  nLenNeed,
const TYPE pData 
)
inlinestatic

Get thread local temp space.

  • nLenNeed = will add a space for '\0'

◆ GetTempSV()

static void* __stdcall Gray::cTempPool::GetTempSV ( size_t  nLenNeed,
const void *  pData 
)
inlinestatic

Get thread local temp space.

◆ GetTempT() [1/2]

template<typename TYPE >
TYPE* Gray::cTempPool::GetTempT ( StrLen_t  nLenNeed)
inline
  • nLenNeed = will add a space for '\0'

◆ GetTempT() [2/2]

template<typename TYPE >
TYPE* Gray::cTempPool::GetTempT ( StrLen_t  nLenNeed,
const TYPE pData 
)
inline
  • nLenNeed = will add a space for '\0'

◆ GetTempV() [1/2]

void * Gray::cTempPool::GetTempV ( size_t  nLenNeed)

Get a temporary/scratch memory space for random uses. Non leaking pointer return. beware of k_iCountMax. Ideally we use should CString(x).get_CPtr() instead. Typically used to hold "%s" argument conversions for StrT::sprintfN() type operations.

  • nLenNeed = exact size (in bytes) including space for '\0'

◆ GetTempV() [2/2]

void * Gray::cTempPool::GetTempV ( size_t  nLenNeed,
const void *  pData 
)

Member Data Documentation

◆ k_iCountMax

const int Gray::cTempPool::k_iCountMax = 16
static

Assume nested functions won't use more than m_aBlocks in a single thread. (e.g. This is the max number of args on a single sprintf)

◆ m_aBlocks

cArrayStruct<cHeapBlock> Gray::cTempPool::m_aBlocks

Temporary blocks to be used on a single thread.

◆ m_iCountCur

int Gray::cTempPool::m_iCountCur

rotate this count to re-use buffers in m_aBlocks.

◆ sm_pThreadLocal

IThreadLocal * Gray::cTempPool::sm_pThreadLocal = &cTempPool::sm_ThreadLocalDefault
static

Allow this to be overloaded with a version that destructs on thread close.

◆ sm_ThreadLocalDefault

cThreadLocalSysNew< cTempPool > Gray::cTempPool::sm_ThreadLocalDefault
static

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