Jpp  19.1.0-rc.1
the software that should make you happy
Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
JLANG::JObjectAllocator< T, JAllocator_t > Class Template Reference

Base class for customized new/delete operators. More...

#include <JObjectAllocator.hh>

Static Public Member Functions

static JAllocator_t & getInstance ()
 Get reference to unique instance of this class object. More...
 
static void * operator new (const std::size_t size)
 new operator. More...
 
static void operator delete (void *p, const std::size_t size)
 delete operator. More...
 

Static Public Attributes

static const std::size_t BLOCK_SIZE = sizeof(T)
 size of object [Byte] More...
 

Protected Member Functions

 JObjectAllocator ()
 Defaul constructor. More...
 

Detailed Description

template<class T, class JAllocator_t>
class JLANG::JObjectAllocator< T, JAllocator_t >

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<A, JRAM> {
     };

In this case, the new/delete operations are implemented by the JLANG::JRAM class.

Definition at line 31 of file JObjectAllocator.hh.

Constructor & Destructor Documentation

◆ JObjectAllocator()

template<class T , class JAllocator_t >
JLANG::JObjectAllocator< T, JAllocator_t >::JObjectAllocator ( )
inlineprotected

Defaul constructor.

Definition at line 37 of file JObjectAllocator.hh.

38  {}

Member Function Documentation

◆ getInstance()

template<class T , class JAllocator_t >
static JAllocator_t& JLANG::JObjectAllocator< T, JAllocator_t >::getInstance ( )
inlinestatic

Get reference to unique instance of this class object.

Returns
reference to this class object

Definition at line 46 of file JObjectAllocator.hh.

47  {
48  static JAllocator_t allocator(BLOCK_SIZE);
49 
50  return allocator;
51  }
static const std::size_t BLOCK_SIZE
size of object [Byte]

◆ operator new()

template<class T , class JAllocator_t >
static void* JLANG::JObjectAllocator< T, JAllocator_t >::operator new ( const std::size_t  size)
inlinestatic

new operator.

Returns
pointer to new object (or NULL)

Definition at line 62 of file JObjectAllocator.hh.

63  {
64  return getInstance().allocate();
65  }
static JAllocator_t & getInstance()
Get reference to unique instance of this class object.

◆ operator delete()

template<class T , class JAllocator_t >
static void JLANG::JObjectAllocator< T, JAllocator_t >::operator delete ( void *  p,
const std::size_t  size 
)
inlinestatic

delete operator.

Parameters
ppointer to object to be freed
sizenumber of bytes

Definition at line 74 of file JObjectAllocator.hh.

75  {
76  getInstance().free(p);
77  }

Member Data Documentation

◆ BLOCK_SIZE

template<class T , class JAllocator_t >
const std::size_t JLANG::JObjectAllocator< T, JAllocator_t >::BLOCK_SIZE = sizeof(T)
static

size of object [Byte]

Definition at line 54 of file JObjectAllocator.hh.


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