Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JObjectAllocator.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JOBJECTALLOCATOR__
2 #define __JLANG__JOBJECTALLOCATOR__
3 
4 /**
5  * \file
6  * Auxiliary base class to speed up new/delete operations of any class.
7  * \author mdejong
8  */
9 namespace JLANG {}
10 namespace JPP { using namespace JLANG; }
11 
12 namespace JLANG {
13 
14  /**
15  * Base class for customized new/delete operators.
16  * The first template argument refers to the data type for new/delete operations and
17  * the second to the memory management class.
18  *
19  * Possible syntax:
20  * <pre>
21  * \#include "JLang/JRAM.hh"
22  *
23  * class A : public JLANG::JObjectAllocator<A, JRAM> {
24  * };
25  * </pre>
26  * In this case, the new/delete operations are implemented by the JLANG::JRAM class.
27  */
28  template<class T, class JAllocator_t>
30  {
31  protected:
32  /**
33  * Defaul constructor.
34  */
36  {}
37 
38  public:
39  /**
40  * Get reference to unique instance of this class object.
41  *
42  * \return reference to this class object
43  */
44  static inline JAllocator_t& getInstance()
45  {
46  static JAllocator_t allocator(BLOCK_SIZE);
47 
48  return allocator;
49  }
50 
51 
52  static const std::size_t BLOCK_SIZE = sizeof(T); //!< size of object [Byte]
53 
54 
55  /**
56  * new operator.
57  *
58  * \return pointer to new object (or NULL)
59  */
60  static inline void* operator new(const std::size_t size)
61  {
62  return getInstance().allocate();
63  }
64 
65 
66  /**
67  * delete operator.
68  *
69  * \param p pointer to object to be freed
70  * \param size number of bytes
71  */
72  static inline void operator delete(void* p, const std::size_t size)
73  {
74  getInstance().free(p);
75  }
76  };
77 }
78 
79 #endif
static const std::size_t BLOCK_SIZE
size of object [Byte]
JObjectAllocator()
Defaul constructor.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
static JAllocator_t & getInstance()
Get reference to unique instance of this class object.
Base class for customized new/delete operators.