7 #ifndef __core_PoolAllocator_h__ 8 #define __core_PoolAllocator_h__ 23 #define HDR_TO_BLK(x) ((void *)((char *)x + sizeof(size_t))) 24 #define BLK_TO_HDR(x) ((void *)((char *)x - sizeof(size_t))) 26 class FE_DL_EXPORT PoolAllocator :
public Allocator
30 PoolAllocator(FE_UWORD stride, FE_UWORD slots);
31 virtual ~PoolAllocator(
void);
32 virtual void *allocate(FE_UWORD byteCount);
33 virtual void deallocate(
void* pMemory);
40 inline void *PoolAllocator::allocate(FE_UWORD byteCount)
42 if(byteCount == 0) {
return NULL; }
43 size_t s = (byteCount-1)/m_stride;
44 if(s < m_max && m_nfList[s])
46 void *pBase = m_nfList[s];
47 m_nfList[s] = ((FE_PA_FREE *)(pBase))->m_next;
48 ((FE_PA_USED *)(pBase))->m_s = s;
49 return (
void *)(HDR_TO_BLK(pBase));
53 void *pBase = fe::allocate(((s+1)*m_stride)+
sizeof(FE_UWORD));
54 ((FE_PA_USED *)(pBase))->m_s = s;
55 return (
void *)(HDR_TO_BLK(pBase));
59 inline void PoolAllocator::deallocate(
void* pMemory)
61 FE_UWORD s = ((FE_PA_USED *)BLK_TO_HDR(pMemory))->m_s;
64 void *pBase = BLK_TO_HDR(pMemory);
65 ((FE_PA_FREE *)(pBase))->m_next = m_nfList[s];
70 fe::deallocate(BLK_TO_HDR(pMemory));
kernel
Definition: namespace.dox:3