1 ///////////////////////////////////////////////////////////////////////////////
2 // $Source: x:/prj/tech/libsrc/lgalloc/RCS/poolimp.h $
4 // $Date: 1997/08/14 12:22:16 $
7 // Implementation details of allocation pools. Most clients should only
8 // concern themselves with pool.h
19 ///////////////////////////////////////////////////////////////////////////////
21 // Macros to specify how pools should get thier memory.
25 #define PoolCoreAllocPage() malloc(kPageSize)
26 #define PoolCoreFreePage(p) free(p)
28 #define PoolCoreAllocPage() cPoolCore::AllocPage()
29 #define PoolCoreFreePage(p) cPoolCore::FreePage(p)
32 ///////////////////////////////////////////////////////////////////////////////
34 // CLASS: cPoolAllocator
36 // Pooled Allocator to be used by operator new, operator delete overrides and
39 // cPoolAllocator will keep a freelist of items of the same size.
40 // When the freelist is empty it will alloc them in multiple blocks
42 // Instances of cPoolAllocator *must* be staticly allocated,
43 // typically as static instance variables of the client class,
44 // as there is no destructor and thus there would be a memory leak if NOT static.
54 cPoolAllocator(size_t elemSize
); // How big will each item be, and howMany per alloc()'d Bucket
56 void Init(size_t elemSize
);
63 static void DumpPools();
66 // For debugging/optimization:
67 unsigned long GetBlockNum();
68 unsigned long GetTakes();
69 unsigned long GetBlockSize();
70 unsigned long GetFrees();
71 unsigned long GetMaxTakes();
75 void ThreadNewBlock();
77 sPoolBlock
* m_pFreeList
;
78 size_t m_nElementSize
;
79 unsigned m_nBlockingFactor
;
81 cPoolAllocator
* m_pNextPool
;
84 unsigned long m_nBlocks
;
85 unsigned long m_nInUse
;
86 unsigned long m_nAllocs
;
87 unsigned long m_nFrees
;
88 unsigned long m_nMaxTakes
;
89 sPoolBlock
* m_pAllocList
;
92 static cPoolAllocator
* m_pPools
;
95 ///////////////////////////////////////
97 inline cPoolAllocator::cPoolAllocator()
102 ///////////////////////////////////////
104 inline cPoolAllocator::cPoolAllocator(size_t elemSize
)
109 ///////////////////////////////////////
112 inline unsigned long cPoolAllocator::GetBlockNum()
117 ///////////////////////////////////////
119 inline unsigned long cPoolAllocator::GetTakes()
124 ///////////////////////////////////////
126 inline unsigned long cPoolAllocator::GetFrees()
131 ///////////////////////////////////////
133 inline unsigned long cPoolAllocator::GetMaxTakes()
139 ///////////////////////////////////////////////////////////////////////////////
141 #endif /* !__POOLIMP_H */