Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JMemory.hh
Go to the documentation of this file.
1#ifndef __JLANG__JMEMORY__
2#define __JLANG__JMEMORY__
3
4#include <stdlib.h>
5
6
7/**
8 * \file
9 *
10 * Base class for memory management.
11 * \author mdejong
12 */
13namespace JLANG {}
14namespace JPP { using namespace JLANG; }
15
16namespace JLANG {
17
18
19 /**
20 * Memory management class for create/release policy based on new/delete.
21 */
22 template<class JClass_t>
23 class JNew {
24 public:
25 /**
26 * Create object in memory.
27 *
28 * \return pointer to data
29 */
30 static inline JClass_t* create()
31 {
32 return new JClass_t();
33 }
34
35
36 /**
37 * Release memory.
38 *
39 * \param p pointer to data
40 */
41 static inline void release(JClass_t* p)
42 {
43 delete p;
44 }
45 };
46
47
48 /**
49 * Memory management class for create/release policy based on new []/delete [].
50 */
51 template<class JClass_t>
52 class JNewCArray {
53 public:
54 /**
55 * Create array of objects in memory.
56 *
57 * \param size number of elements
58 * \return pointer to data
59 */
60 static inline JClass_t* create(const unsigned int size)
61 {
62 return new JClass_t[size];
63 }
64
65
66 /**
67 * Release memory.
68 *
69 * \param p pointer to data
70 */
71 static inline void release(JClass_t* p)
72 {
73 delete [] p;
74 }
75 };
76
77
78 /**
79 * Memory management class for create/release policy based on malloc()/free().
80 */
81 template<class JClass_t>
82 class JMalloc {
83 public:
84 /**
85 * Create object in memory.
86 *
87 * \return pointer to data
88 */
89 static inline JClass_t* create()
90 {
91 return (JClass_t*) malloc(sizeof(JClass_t));
92 }
93
94
95 /**
96 * Create array of objects in memory.
97 *
98 * \param size number of elements
99 * \return pointer to data
100 */
101 static inline JClass_t* create(const unsigned int size)
102 {
103 return (JClass_t*) malloc(size * sizeof(JClass_t));
104 }
105
106
107 /**
108 * Release memory.
109 *
110 * \param p pointer to data
111 */
112 static inline void release(JClass_t* p)
113 {
114 free((void*) p);
115 }
116 };
117}
118
119
120#endif
Memory management class for create/release policy based on malloc()/free().
Definition JMemory.hh:82
static JClass_t * create()
Create object in memory.
Definition JMemory.hh:89
static void release(JClass_t *p)
Release memory.
Definition JMemory.hh:112
static JClass_t * create(const unsigned int size)
Create array of objects in memory.
Definition JMemory.hh:101
Memory management class for create/release policy based on new []/delete [].
Definition JMemory.hh:52
static JClass_t * create(const unsigned int size)
Create array of objects in memory.
Definition JMemory.hh:60
static void release(JClass_t *p)
Release memory.
Definition JMemory.hh:71
Memory management class for create/release policy based on new/delete.
Definition JMemory.hh:23
static JClass_t * create()
Create object in memory.
Definition JMemory.hh:30
static void release(JClass_t *p)
Release memory.
Definition JMemory.hh:41
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).