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 namespace P6R {
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define MEMPOOL_FREE_VALUE 0xdd
27 #define P6MEMPOOL_NAME_MAX 32
28 
29 /* -------------------------------------------------------------------------- */
30 /* IPool interface definition */
31 /* -------------------------------------------------------------------------- */
33 const MEMPOOLFLGS MEMPOOL_NOFLAGS = 0x00000000;
34 const MEMPOOLFLGS MEMPOOL_ZEROMEM = 0x00000001;
35 const MEMPOOLFLGS MEMPOOL_USEHEAP = 0x00000002;
36 const MEMPOOLFLGS MEMPOOL_SETFREEMEM = 0x00000004;
37 const MEMPOOLFLGS MEMPOOL_ENABLEFENCES = 0x00000008;
38 const MEMPOOLFLGS MEMPOOL_NOLOCKS = 0x00000010;
39 const MEMPOOLFLGS MEMPOOL_ENABLEDEBUG = (MEMPOOL_ZEROMEM|MEMPOOL_SETFREEMEM|MEMPOOL_ENABLEFENCES);
65 interface p6IMemPool : p6ICom
66 {
106  P6COMMETHOD initialize(MEMPOOLFLGS nFlags,
107  P6R::P6UINT32 cPageSize,
108  P6R::P6UINT32 cInitialCount,
109  P6R::P6UINT32 cGrowBy,
110  const P6R::P6WCHAR *pszName) = 0;
111 
121  P6COMMETHOD alloc(P6R::P6VOID **ppMem) = 0;
122 
123 
133  P6COMMETHOD free(P6R::P6VOID *pMem) = 0;
134 
160  P6R::P6UINT32 *pcActual,
161  P6R::P6UINT32 *pcInitial,
162  P6R::P6UINT32 *pcGrowby,
163  P6R::P6UINT32 *pcTotal,
164  P6R::P6UINT32 *pcFree,
165  P6R::P6UINT32 *pcHighWater) = 0;
166 
167 
180  P6COMMETHOD isOwned(P6R::P6VOID *pMem) = 0;
181 
182 
196  P6COMMETHOD getName(P6R::P6WCHAR *pBuffer,P6R::P6UINT32 *pcBuffer) = 0;
197 };
198 
199 // {3FE25F49-9400-4aec-9D8C-E83747C10F6C}
200 #define IF_p6IMemPool {0x3FE25F49,0x9400,0x4aec,{0x9D,0x8C,0xE8,0x37,0x47,0xC1,0x0F,0x6C}}
201 
202 // {D521E1E5-5A61-47c0-931A-003AF5D613A0}
203 #define COMP_p6MemPool {0xD521E1E5,0x5A61,0x47c0,{0x93,0x1A,0x00,0x3A,0xF5,0xD6,0x13,0xA0}}
204 
205 #ifdef __cplusplus
206 }
207 
208 template<class T> class typedMemPool {
209  p6IMemPool *m_pPool;
210  public:
211  typedMemPool() : m_pPool(NULL)
212  { }
214  { if(NULL != m_pPool) m_pPool->release(); m_pPool = NULL; }
215  P6R::P6ERR initialize(MEMPOOLFLGS nFlags,P6R::P6UINT32 uiInitial,P6R::P6UINT32 uiGrowby,const P6R::P6WCHAR *pszName)
216  {
217  P6R::P6ERR err;
218  P6DECLARE_CID(p6MemPool);
220  if(P6SUCCEEDED(err = p6CreateInstance(NULL,CID_p6MemPool,VALIDATEIF(p6IMemPool,&m_pPool)))) {
221  err = m_pPool->initialize(nFlags,sizeof(T),uiInitial,uiGrowby,pszName);
222  }
223  return err;
224  }
225  P6R::P6ERR alloc(T **ppMem)
226  { if(m_pPool) return m_pPool->alloc((void**)ppMem);else return eNotInitialized; }
227  P6R::P6ERR free(T *pMem)
228  { if(m_pPool) return m_pPool->free((void*)pMem); else return eNotInitialized; }
229  P6R::P6ERR getStats(P6R::P6UINT32 *pcBlock,P6R::P6UINT32 *pcActual,P6R::P6UINT32 *pcInitial,P6R::P6UINT32 *pcGrowby,P6R::P6UINT32 *pcTotal,P6R::P6UINT32 *pcFree,P6R::P6UINT32 *pcHighWater)
230  {if(m_pPool) return m_pPool->getStats(pcBlock,pcActual,pcInitial,pcGrowby,pcTotal,pcFree,pcHighWater); else return eNotInitialized; }
231 };
232 
233 #endif
234 } // namespace
235 
236 #endif
237 
238 
const MEMPOOLFLGS MEMPOOL_NOLOCKS
Disable serialization.
Definition: p6mempool.h:38
#define P6DECLARE_CID(component)
Defines a component identifier.
Definition: p6types.h:817
P6R::P6ERR alloc(T **ppMem)
Definition: p6mempool.h:225
unsigned int P6UINT32
Definition: p6types.h:40
P6API P6R::P6ERR p6CreateInstance(P6R::p6ICom *pOuter, const P6R::CID &cid, const P6R::IID &iid, P6R::P6VOID **ppIface)
Creates a single uninitialized instance of the class/interface associated with the specified componen...
virtual P6R::P6INT32 release()=0
This method decrements a components reference count.
virtual P6R::P6ERR isOwned(P6R::P6VOID *pMem)=0
This method is used to determine if the specified memory belongs to this memory pool.
P6R::P6UINT32 MEMPOOLFLGS
Definition: p6mempool.h:32
P6R::P6ERR initialize(MEMPOOLFLGS nFlags, P6R::P6UINT32 uiInitial, P6R::P6UINT32 uiGrowby, const P6R::P6WCHAR *pszName)
Definition: p6mempool.h:215
#define VALIDATEIF(type, ptr)
Only include this when generating documentation.
Definition: p6comhlpr.h:52
virtual P6R::P6ERR getStats(P6R::P6UINT32 *pcBlock, P6R::P6UINT32 *pcActual, P6R::P6UINT32 *pcInitial, P6R::P6UINT32 *pcGrowby, P6R::P6UINT32 *pcTotal, P6R::P6UINT32 *pcFree, P6R::P6UINT32 *pcHighWater)=0
Retrieves current statistical information for the memory pool.
virtual P6R::P6ERR free(P6R::P6VOID *pMem)=0
Returns an allocation back to the pool and makes it available to be allocated via alloc()...
#define P6DECLARE_IID(iface)
Defines a Interface Identifier.
Definition: p6types.h:810
const MEMPOOLFLGS MEMPOOL_NOFLAGS
Definition: p6mempool.h:33
wchar_t P6WCHAR
Wide character type see p6i18n.h.
Definition: p6types.h:76
The base interface all [p6]COM components must derive from and implement.
Definition: p6comdef.h:96
virtual P6R::P6ERR getName(P6R::P6WCHAR *pBuffer, P6R::P6UINT32 *pcBuffer)=0
Get the name of the memory which was provide by the intialization method.
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:229
const MEMPOOLFLGS MEMPOOL_USEHEAP
Pooling disabled, allocs are done from heap directly, also disables serialization within the memory p...
Definition: p6mempool.h:35
virtual P6R::P6ERR initialize(MEMPOOLFLGS nFlags, P6R::P6UINT32 cPageSize, P6R::P6UINT32 cInitialCount, P6R::P6UINT32 cGrowBy, const P6R::P6WCHAR *pszName)=0
This method is called to initialize the memory pool for use.
This is a fixed size memory allocator.
Definition: p6mempool.h:65
const MEMPOOLFLGS MEMPOOL_ENABLEDEBUG
Turn on all debug params.
Definition: p6mempool.h:39
P6UINT32 P6ERR
COM err return type see P6ERR.h.
Definition: p6types.h:109
P6R::P6ERR free(T *pMem)
Definition: p6mempool.h:227
#define P6SUCCEEDED(err)
Definition: p6err.h:50
#define P6COMMETHOD
Definition: p6types.h:872
const MEMPOOLFLGS MEMPOOL_ZEROMEM
Alloc() returns zero&#39;d memory.
Definition: p6mempool.h:34
const MEMPOOLFLGS MEMPOOL_ENABLEFENCES
Enable under/overrun detection.
Definition: p6mempool.h:37
P6COM definitions and interfaces.
const MEMPOOLFLGS MEMPOOL_SETFREEMEM
Set free blocks to MEMPOOL_FREE_VALUE for debugging.
Definition: p6mempool.h:36
virtual P6R::P6ERR alloc(P6R::P6VOID **ppMem)=0
Allocates am allocation unit from the memory pool.
void P6VOID
Definition: p6types.h:75