Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cTempPool.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_cTempPool_H
6 #define _INC_cTempPool_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "cArray.h"
12 #include "cHeap.h"
13 #include "cThreadLocalSys.h"
14 
15 namespace Gray
16 {
18  {
27 
28  public:
31 
32  static const int k_iCountMax = 16;
33 
35  static IThreadLocal* sm_pThreadLocal; // can use cThreadLocalTypeNew instead.
36  static cThreadLocalSysNew<cTempPool> sm_ThreadLocalDefault; // default for sm_pThreadLocal. set sm_pThreadLocal with cThreadLocalTypeNew in more strict applications.
37 
38  public:
40  : m_iCountCur(0)
41  {
42  }
43  virtual ~cTempPool()
44  {
45  }
46 
47  void CleanTemps();
48  void* GetTempV(size_t nLenNeed); // get void/bytes.
49  void* GetTempV(size_t nLenNeed, const void* pData);
50 
51  template< typename TYPE>
52  inline TYPE* GetTempT(StrLen_t nLenNeed)
53  {
55  return (TYPE*)(GetTempV((nLenNeed + 1) * sizeof(TYPE)));
56  }
57  template< typename TYPE>
58  inline TYPE* GetTempT(StrLen_t nLenNeed, const TYPE* pData)
59  {
61  return (TYPE*)(GetTempV((nLenNeed + 1) * sizeof(TYPE), pData));
62  }
63 
64  static cTempPool* GRAYCALL GetTempPool();
65  static void GRAYCALL FreeTempsForThreadManually();
66 
67  static void* GRAYCALL GetTempSV(size_t nLenNeed, const void* pData) // static
68  {
70  return GetTempPool()->GetTempV(nLenNeed,pData);
71  }
72 
73  template< typename TYPE>
74  static TYPE* GRAYCALL GetTempST(StrLen_t nLenNeed)
75  {
78  return GetTempPool()->GetTempT<TYPE>(nLenNeed);
79  }
80  template< typename TYPE>
81  static TYPE* GRAYCALL GetTempST(StrLen_t nLenNeed, const TYPE* pData)
82  {
85  return GetTempPool()->GetTempT<TYPE>(nLenNeed, pData);
86  }
87  };
88 }
89 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define TYPE
Definition: StrT.cpp:38
Definition: cArray.h:932
Definition: cTempPool.h:18
static TYPE *__stdcall GetTempST(StrLen_t nLenNeed, const TYPE *pData)
Definition: cTempPool.h:81
static TYPE *__stdcall GetTempST(StrLen_t nLenNeed)
Definition: cTempPool.h:74
virtual ~cTempPool()
Definition: cTempPool.h:43
static IThreadLocal * sm_pThreadLocal
Allow this to be overloaded with a version that destructs on thread close.
Definition: cTempPool.h:35
static void *__stdcall GetTempSV(size_t nLenNeed, const void *pData)
Definition: cTempPool.h:67
cArrayStruct< cHeapBlock > m_aBlocks
Temporary blocks to be used on a single thread.
Definition: cTempPool.h:30
static cThreadLocalSysNew< cTempPool > sm_ThreadLocalDefault
Definition: cTempPool.h:36
int m_iCountCur
rotate this count to re-use buffers in m_aBlocks.
Definition: cTempPool.h:29
cTempPool()
Definition: cTempPool.h:39
TYPE * GetTempT(StrLen_t nLenNeed)
Definition: cTempPool.h:52
TYPE * GetTempT(StrLen_t nLenNeed, const TYPE *pData)
Definition: cTempPool.h:58
Definition: cThreadLocalSys.h:179
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
Definition: cThreadLocalSys.h:30