server/src/mem_pool.cpp
/*==========================================================
CMemPool:
    Constructor of this class. It allocate memory block from system and create
    a static double linked list to manage all memory unit.

Parameters:
    [in]ulUnitNum
    The number of unit which is a part of memory block.

    [in]ulUnitSize
    The size of unit.
//=========================================================
*/
Constructor of this class. It allocate memory block from system and create
a static double linked list to manage all memory unit.

[in]ulUnitNum
The number of unit which is a part of memory block.

[in]ulUnitSize
The size of unit.
Constructor of this class . It allocate memory block from system and create a static double linked list to manage all memory unit . [ in ] ulUnitNum The number of unit which is a part of memory block . [ in ] ulUnitSize The size of unit .
CMemPool::CMemPool(unsigned long ulUnitNum,unsigned long ulUnitSize) :
    m_pMemBlock(NULL), m_pAllocatedMemBlock(NULL), m_pFreeMemBlock(NULL), 
    m_ulBlockSize(ulUnitNum * (ulUnitSize+sizeof(struct _Unit))), 
    m_ulUnitSize(ulUnitSize)
{    
    m_pMemBlock = malloc(m_ulBlockSize);     
    if(NULL != m_pMemBlock)
    {
        for(unsigned long i=0; i<ulUnitNum; i++)  
        {
            struct _Unit *pCurUnit = (struct _Unit *)( (char *)m_pMemBlock + i*(ulUnitSize+sizeof(struct _Unit)) );
            pCurUnit->pPrev = NULL;
            pCurUnit->pNext = m_pFreeMemBlock;    
            if(NULL != m_pFreeMemBlock)
            {
                m_pFreeMemBlock->pPrev = pCurUnit;
            }
            m_pFreeMemBlock = pCurUnit;
        }
    }    
}
CMemPool :: CMemPool ( unsigned long ulUnitNum , unsigned long ulUnitSize ) : m_pMemBlock ( NULL ) , m_pAllocatedMemBlock ( NULL ) , m_pFreeMemBlock ( NULL ) , m_ulBlockSize ( ulUnitNum * ( ulUnitSize + sizeof ( struct _Unit ) ) ) , m_ulUnitSize ( ulUnitSize ) { m_pMemBlock = malloc ( m_ulBlockSize ) ; if ( NULL != m_pMemBlock ) { for ( unsigned long i = 0 ; i < ulUnitNum ; i ++ ) { struct _Unit * pCurUnit = ( struct _Unit * ) ( ( char * ) m_pMemBlock + i * ( ulUnitSize + sizeof ( struct _Unit ) ) ) ; pCurUnit -> pPrev = NULL ; pCurUnit -> pNext = m_pFreeMemBlock ; if ( NULL != m_pFreeMemBlock ) { m_pFreeMemBlock -> pPrev = pCurUnit ; } m_pFreeMemBlock = pCurUnit ; } } }
CMemPool:
Constructor of this class.
CMemPool : Constructor of this class .
//Allocate a memory block. //Link all mem unit . Create linked list. //Insert the new unit at head.