Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
p6mempool.h
Go to the documentation of this file.
1 
15 #ifndef P6MEMPOOL_H__
16 #define P6MEMPOOL_H__ 1
17 
18 #include "p6com.h"
19 
20 #ifdef __cplusplus
21 namespace P6R {
22 extern "C" {
23 #endif
24 
25  #define MEMPOOL_FREE_VALUE 0xdd
26  #define P6MEMPOOL_NAME_MAX 32
27 
28  /* -------------------------------------------------------------------------- */
29  /* IPool interface definition */
30  /* -------------------------------------------------------------------------- */
32  const MEMPOOLFLGS MEMPOOL_NOFLAGS = 0x00000000;
33  const MEMPOOLFLGS MEMPOOL_ZEROMEM = 0x00000001;
34  const MEMPOOLFLGS MEMPOOL_USEHEAP = 0x00000002;
35  const MEMPOOLFLGS MEMPOOL_SETFREEMEM = 0x00000004;
36  const MEMPOOLFLGS MEMPOOL_ENABLEFENCES = 0x00000008;
37  const MEMPOOLFLGS MEMPOOL_NOLOCKS = 0x00000010;
38 // const MEMPOOLFLGS MEMPOOL_ENABLEDEBUG = (MEMPOOL_ZEROMEM|MEMPOOL_SETFREEMEM|MEMPOOL_ENABLEFENCES); /**< Turn on all debug params */
39 
40 
64  #undef INTERFACE
65  #define INTERFACE p6IMemPool
67  {
69 
109  P6DECLCOMMETHOD(initialize)(P6THIS_ MEMPOOLFLGS nFlags,
110  P6UINT32 cPageSize,
111  P6UINT32 cInitialCount,
112  P6UINT32 cGrowBy,
113  const P6WCHAR *pszName) P6PURE;
114 
124  P6DECLCOMMETHOD(alloc)(P6THIS_ P6VOID **ppMem) P6PURE;
125 
126 
136  P6DECLCOMMETHOD(free)(P6THIS_ P6VOID *pMem) P6PURE;
137 
162  P6DECLCOMMETHOD(getStats)(P6THIS_ P6UINT32 *pcBlock,
163  P6UINT32 *pcActual,
164  P6UINT32 *pcInitial,
165  P6UINT32 *pcGrowby,
166  P6UINT32 *pcTotal,
167  P6UINT32 *pcFree,
168  P6UINT32 *pcHighWater) P6PURE;
169 
170 
183  P6DECLCOMMETHOD(isOwned)(P6THIS_ P6VOID *pMem) P6PURE;
184 
185 
199  P6DECLCOMMETHOD(getName)(P6THIS_ P6WCHAR *pBuffer,P6UINT32 *pcBuffer) P6PURE;
200  };
201 
202  // {3FE25F49-9400-4aec-9D8C-E83747C10F6C}
203  #define IF_p6IMemPool {0x3FE25F49,0x9400,0x4aec,{0x9D,0x8C,0xE8,0x37,0x47,0xC1,0x0F,0x6C}}
204 
205  // {D521E1E5-5A61-47c0-931A-003AF5D613A0}
206  #define COMP_p6MemPool {0xD521E1E5,0x5A61,0x47c0,{0x93,0x1A,0x00,0x3A,0xF5,0xD6,0x13,0xA0}}
207 
208 #ifdef __cplusplus
209 } /* extern "C" */
210 
211  template<class T> class typedMemPool {
212  p6IMemPool *m_pPool;
213  public:
214  typedMemPool() : m_pPool(NULL)
215  { }
217  { if(NULL != m_pPool) m_pPool->release(); m_pPool = NULL; }
218  P6R::P6ERR initialize(MEMPOOLFLGS nFlags,P6R::P6UINT32 uiInitial,P6R::P6UINT32 uiGrowby,const P6R::P6WCHAR *pszName)
219  {
220  P6R::P6ERR err;
221  P6DECLARE_CID(p6MemPool);
223  if(P6SUCCEEDED(err = p6CreateInstance(NULL,CID_p6MemPool,VALIDATEIF(p6IMemPool,&m_pPool)))) {
224  err = m_pPool->initialize(nFlags,sizeof(T),uiInitial,uiGrowby,pszName);
225  }
226  return err;
227  }
228  P6R::P6ERR alloc(T **ppMem)
229  { if(m_pPool) return m_pPool->alloc((void**)ppMem);else return eNotInitialized; }
230  P6R::P6ERR free(T *pMem)
231  { if(m_pPool) return m_pPool->free((void*)pMem); else return eNotInitialized; }
232  P6R::P6ERR getStats(P6R::P6UINT32 *pcBlock,P6R::P6UINT32 *pcActual,P6R::P6UINT32 *pcInitial,P6R::P6UINT32 *pcGrowby,P6R::P6UINT32 *pcTotal,P6R::P6UINT32 *pcFree,P6R::P6UINT32 *pcHighWater)
233  {if(m_pPool) return m_pPool->getStats(pcBlock,pcActual,pcInitial,pcGrowby,pcTotal,pcFree,pcHighWater); else return eNotInitialized; }
234  };
235 
236 } // namespace
237 #endif
238 
239 #endif
240 
241 
#define P6DECLARE_CID(component)
Defines a component identifier.
Definition: p6defs.h:172
const MEMPOOLFLGS MEMPOOL_NOLOCKS
Disable serialization.
Definition: p6mempool.h:37
P6R::P6ERR alloc(T **ppMem)
Definition: p6mempool.h:228
uint32_t P6UINT32
Definition: p6types.h:77
#define P6DECLAREICOM
Definition: p6defs.h:191
P6UINT32 MEMPOOLFLGS
Definition: p6mempool.h:31
#define P6PURE
Definition: p6defs.h:192
virtual P6R::P6ERR alloc(P6VOID **ppMem)=0
Allocates am allocation unit from the memory pool.
#define P6DECLARE_IID(iface)
Defines a Interface Identifier.
Definition: p6defs.h:166
P6R::P6ERR initialize(MEMPOOLFLGS nFlags, P6R::P6UINT32 uiInitial, P6R::P6UINT32 uiGrowby, const P6R::P6WCHAR *pszName)
Definition: p6mempool.h:218
#define VALIDATEIF(type, ptr)
std::nothrow
Definition: p6comhlpr.h:55
virtual P6INT32 release(void)=0
This method decrements a components reference count.
const MEMPOOLFLGS MEMPOOL_NOFLAGS
Definition: p6mempool.h:32
wchar_t P6WCHAR
Wide character type see p6i18n.h.
Definition: p6types.h:111
The base interface all [p6]COM components must derive from and implement.
Definition: p6comdef.h:97
P6API P6ERR P6CCALL p6CreateInstance(p6ICom *pOuter, const P6R::P6CID &cid, const P6R::P6IID &iid, P6VOID **ppIface)
Creates a single uninitialized instance of the class/interface associated with the specified componen...
P6R::P6ERR getStats(P6R::P6UINT32 *pcBlock, P6R::P6UINT32 *pcActual, P6R::P6UINT32 *pcInitial, P6R::P6UINT32 *pcGrowby, P6R::P6UINT32 *pcTotal, P6R::P6UINT32 *pcFree, P6R::P6UINT32 *pcHighWater)
Definition: p6mempool.h:232
virtual P6R::P6ERR free(P6VOID *pMem)=0
Returns an allocation back to the pool and makes it available to be allocated via alloc()...
const MEMPOOLFLGS MEMPOOL_USEHEAP
Pooling disabled, allocs are done from heap directly, also disables serialization within the memory p...
Definition: p6mempool.h:34
This is a fixed size memory allocator.
Definition: p6mempool.h:66
P6UINT32 P6ERR
COM err return type see P6ERR.h.
Definition: p6types.h:141
P6R::P6ERR free(T *pMem)
Definition: p6mempool.h:230
#define P6SUCCEEDED(err)
Definition: p6err.h:49
#define P6DECLCOMMETHOD(method)
Definition: p6defs.h:189
virtual P6R::P6ERR initialize(MEMPOOLFLGS nFlags, P6UINT32 cPageSize, P6UINT32 cInitialCount, P6UINT32 cGrowBy, const P6WCHAR *pszName)=0
This method is called to initialize the memory pool for use.
#define P6THIS_
Definition: p6defs.h:193
const MEMPOOLFLGS MEMPOOL_ZEROMEM
Alloc() returns zero&#39;d memory.
Definition: p6mempool.h:33
const MEMPOOLFLGS MEMPOOL_ENABLEFENCES
Enable under/overrun detection.
Definition: p6mempool.h:36
P6COM definitions and interfaces.
const MEMPOOLFLGS MEMPOOL_SETFREEMEM
Set free blocks to MEMPOOL_FREE_VALUE for debugging.
Definition: p6mempool.h:35
void P6VOID
Definition: p6types.h:109
virtual P6R::P6ERR getStats(P6UINT32 *pcBlock, P6UINT32 *pcActual, P6UINT32 *pcInitial, P6UINT32 *pcGrowby, P6UINT32 *pcTotal, P6UINT32 *pcFree, P6UINT32 *pcHighWater)=0
Retrieves current statistical information for the memory pool.
#define P6DECLAREIF_(iface, baseif)
Definition: p6defs.h:188