Pool< T > Class Template Reference

Pool is a fast allocating buffer of many objects of the same type. More...

#include <MemoryMgmt.h>

Collaboration diagram for Pool< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Pool (int size=0)
bool isNull () const
int size () const
void init (int size)
T * allocate ()
void clear ()
void clearMaxAlloc ()
int getMaxAlloc () const

Private Attributes

T * m_buffers
int m_size
int m_next
int m_allocated
int m_maxAllocated

Detailed Description

template<typename T>
class Pool< T >

Pool is a fast allocating buffer of many objects of the same type.

It is used for memory access optimization in the PicPainter and MyObject. A Pool of objects of type T can be created with a certain size. When a call to allocate() is made, one of those objects is returned. Objects in the pool can't be individually deallocated. instead, the who pool is discarded once there is no more need for the objects allocated in it. This is a really silly garbage collection mechanism. The pool cannot grow above its initial size. if allocate() is called more times then there are items available in the pool, it will return an object which is allocated individually outside the pool. This object is likely to be leaked since there is no direct indication to the user of this situation. The user can detect an overallocation (and possibly prevent it although this is not done) by comparing size() with getMaxAlloc()

See also:
MyAllocator


Constructor & Destructor Documentation

template<typename T>
Pool< T >::Pool ( int  size = 0  )  [inline]


Member Function Documentation

template<typename T>
bool Pool< T >::isNull (  )  const [inline]

template<typename T>
int Pool< T >::size (  )  const [inline]

template<typename T>
void Pool< T >::init ( int  size  )  [inline]

template<typename T>
T* Pool< T >::allocate (  )  [inline]

template<typename T>
void Pool< T >::clear (  )  [inline]

template<typename T>
void Pool< T >::clearMaxAlloc (  )  [inline]

template<typename T>
int Pool< T >::getMaxAlloc (  )  const [inline]


Member Data Documentation

template<typename T>
T* Pool< T >::m_buffers [private]

template<typename T>
int Pool< T >::m_size [private]

template<typename T>
int Pool< T >::m_next [private]

template<typename T>
int Pool< T >::m_allocated [private]

template<typename T>
int Pool< T >::m_maxAllocated [private]


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