Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Attributes
btPoolAllocator Class Reference

#include <btPoolAllocator.h>

List of all members.

Public Member Functions

 btPoolAllocator (int elemSize, int maxElements)
 ~btPoolAllocator ()
int getFreeCount () const
void * allocate (int size)
bool validPtr (void *ptr)
void freeMemory (void *ptr)

Private Attributes

int m_elemSize
int m_maxElements
int m_freeCount
void * m_firstFree
unsigned char * m_pool

Detailed Description

Definition at line 22 of file btPoolAllocator.h.


Constructor & Destructor Documentation

btPoolAllocator::btPoolAllocator ( int  elemSize,
int  maxElements 
) [inline]

Definition at line 32 of file btPoolAllocator.h.

              :m_elemSize(elemSize),
              m_maxElements(maxElements)
       {
              m_pool = (unsigned char*) btAlignedAlloc(m_elemSize*m_maxElements,16);

              unsigned char* p = m_pool;
        m_firstFree = p;
        m_freeCount = m_maxElements;
        int count = m_maxElements;
        while (--count) {
            *(void**)p = (p + m_elemSize);
            p += m_elemSize;
        }
        *(void**)p = 0;
    }

Definition at line 49 of file btPoolAllocator.h.

Here is the caller graph for this function:


Member Function Documentation

void* btPoolAllocator::allocate ( int  size) [inline]

Definition at line 59 of file btPoolAllocator.h.

       {
              btAssert(!size || size<=m_elemSize);
              btAssert(m_freeCount>0);
        void* result = m_firstFree;
        m_firstFree = *(void**)m_firstFree;
        --m_freeCount;
        return result;
       }

Here is the caller graph for this function:

void btPoolAllocator::freeMemory ( void *  ptr) [inline]

Definition at line 80 of file btPoolAllocator.h.

       {
               if (ptr) {
            btAssert((unsigned char*)ptr >= m_pool && (unsigned char*)ptr < m_pool + m_maxElements * m_elemSize);

            *(void**)ptr = m_firstFree;
            m_firstFree = ptr;
            ++m_freeCount;
        }
       }

Here is the caller graph for this function:

int btPoolAllocator::getFreeCount ( ) const [inline]

Definition at line 54 of file btPoolAllocator.h.

       {
              return m_freeCount;
       }

Here is the caller graph for this function:

bool btPoolAllocator::validPtr ( void *  ptr) [inline]

Definition at line 69 of file btPoolAllocator.h.

       {
              if (ptr) {
                     if (((unsigned char*)ptr >= m_pool && (unsigned char*)ptr < m_pool + m_maxElements * m_elemSize))
                     {
                            return true;
                     }
              }
              return false;
       }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 24 of file btPoolAllocator.h.

Definition at line 27 of file btPoolAllocator.h.

Definition at line 26 of file btPoolAllocator.h.

Definition at line 25 of file btPoolAllocator.h.

unsigned char* btPoolAllocator::m_pool [private]

Definition at line 28 of file btPoolAllocator.h.


The documentation for this class was generated from the following file: