#ifndef __JLANG__JOBJECTALLOCATOR__
#define __JLANG__JOBJECTALLOCATOR__
/**
* \file
* Auxiliary base class to speed up new/delete operations of any class.
* \author mdejong
*/
namespace JLANG {}
namespace JPP { using namespace JLANG; }
namespace JLANG {
/**
* Base class for customized new/delete operators.
* The first template argument refers to the data type for new/delete operations and
* the second to the memory management class.
*
* Possible syntax:
*
* \#include "JLang/JRAM.hh"
*
* class A : public JLANG::JObjectAllocator {
* };
*
* In this case, the new/delete operations are implemented by the JLANG::JRAM class.
*/
template
class JObjectAllocator
{
protected:
/**
* Defaul constructor.
*/
JObjectAllocator()
{}
public:
/**
* Get reference to unique instance of this class object.
*
* \return reference to this class object
*/
static inline JAllocator_t& getInstance()
{
static JAllocator_t allocator(BLOCK_SIZE);
return allocator;
}
static const std::size_t BLOCK_SIZE = sizeof(T); //!< size of object [Byte]
/**
* new operator.
*
* \return pointer to new object (or NULL)
*/
static inline void* operator new(const std::size_t size)
{
return getInstance().allocate();
}
/**
* delete operator.
*
* \param p pointer to object to be freed
* \param size number of bytes
*/
static inline void operator delete(void* p, const std::size_t size)
{
getInstance().free(p);
}
};
}
#endif