Jpp
software
JLang
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>
29
class
JObjectAllocator
30
{
31
protected
:
32
/**
33
* Defaul constructor.
34
*/
35
JObjectAllocator
()
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
JLANG::JObjectAllocator::getInstance
static JAllocator_t & getInstance()
Get reference to unique instance of this class object.
Definition:
JObjectAllocator.hh:44
JLANG::JObjectAllocator
Base class for customized new/delete operators.
Definition:
JObjectAllocator.hh:29
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition:
JAAnetToolkit.hh:37
JLANG::JObjectAllocator::BLOCK_SIZE
static const std::size_t BLOCK_SIZE
size of object [Byte]
Definition:
JObjectAllocator.hh:52
JLANG
Auxiliary classes and methods for language specific functionality.
Definition:
JAbstractClass.hh:10
JLANG::JObjectAllocator::JObjectAllocator
JObjectAllocator()
Defaul constructor.
Definition:
JObjectAllocator.hh:35
Generated by
1.8.16