Overview     Modules     Class Hierarchy     Classes     Members  

tlp::MemoryPool< TYPE > Class Template Reference

That class enables to easily create a memory pool for an a class. More...

#include <memorypool.h>

List of all members.

Public Member Functions


Detailed Description

template<typename TYPE>
class tlp::MemoryPool< TYPE >

That class enables to easily create a memory pool for an a class.

It allocates chunk of BUFFOBJ size of continous memory to allocate instance of the class. After a delete the memory is not free, and will be reused at the next new of the class.

Warning:
it is not recommended to inherit from an object that inherit of that class

The following code only calls malloc one time even if NBTRY object are created in that example, the speedup is about 23, without MemoryPool malloc is called NBTRY times

 class A : public MemoryPool<A> {
 public:
     A(){}
    ~A(){}
    int data[1000];
 };

 size_t NBTRY = 1000 * 1000;
 for (size_t j=0; j < NBTRY; ++j) {
    A *a = new A();
    a->data[100] = j;
    r1 += a->data[100];
    delete a;
 }

Constructor & Destructor Documentation

template<typename TYPE>
tlp::MemoryPool< TYPE >::MemoryPool (  )  [inline]

Member Function Documentation

template<typename TYPE>
void tlp::MemoryPool< TYPE >::operator delete ( void *  p  )  [inline]
template<typename TYPE>
void* tlp::MemoryPool< TYPE >::operator new ( size_t  sizeofObj  )  [inline]


Tulip Software by LaBRI Visualization Team    2001 - 2011