#include <MemoryMgmt.h>
Collaboration diagram for Pool< T >:
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 |
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()
bool Pool< T >::isNull | ( | ) | const [inline] |
int Pool< T >::size | ( | ) | const [inline] |
void Pool< T >::init | ( | int | size | ) | [inline] |
T* Pool< T >::allocate | ( | ) | [inline] |
void Pool< T >::clear | ( | ) | [inline] |
void Pool< T >::clearMaxAlloc | ( | ) | [inline] |
int Pool< T >::getMaxAlloc | ( | ) | const [inline] |
int Pool< T >::m_allocated [private] |
int Pool< T >::m_maxAllocated [private] |