blob: 2c5b1e73c7b2dd412e3e57bb63c20bd5968ab63a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// Copyright (C) 2006 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_MEMORY_MANAGER_STATELESs_ABSTRACT_
#ifdef DLIB_MEMORY_MANAGER_STATELESs_ABSTRACT_
#include "../algs.h"
namespace dlib
{
template <
typename T
>
class memory_manager_stateless
{
/*!
REQUIREMENTS ON T
T must have a default constructor.
WHAT THIS OBJECT REPRESENTS
This object represents some kind of stateless memory manager or memory pool.
Stateless means that all instances (instances of the same kernel implementation that is)
of this object are identical and can be used interchangeably. Note that
implementations are allowed to have some shared global state such as a
global memory pool.
THREAD SAFETY
This object is thread safe. You may access it from any thread at any time
without synchronizing access.
!*/
public:
typedef T type;
const static bool is_stateless = true;
template <typename U>
struct rebind {
typedef memory_manager_stateless<U> other;
};
memory_manager_stateless(
);
/*!
ensures
- #*this is properly initialized
throws
- std::bad_alloc
!*/
virtual ~memory_manager_stateless(
);
/*!
ensures
- frees any resources used by *this but has no effect on any shared global
resources used by the implementation.
!*/
T* allocate (
);
/*!
ensures
- allocates a new object of type T and returns a pointer to it.
throws
- std::bad_alloc or any exception thrown by T's constructor.
If this exception is thrown then the call to allocate()
has no effect on #*this.
!*/
void deallocate (
T* item
);
/*!
requires
- item == is a pointer to memory that was obtained from a call to
allocate(). (i.e. The pointer you are deallocating must have
come from the same implementation of memory_manager_stateless
that is trying to deallocate it.)
- the memory pointed to by item hasn't already been deallocated.
ensures
- deallocates the object pointed to by item
!*/
T* allocate_array (
unsigned long size
);
/*!
ensures
- allocates a new array of size objects of type T and returns a
pointer to it.
throws
- std::bad_alloc or any exception thrown by T's constructor.
If this exception is thrown then the call to allocate()
has no effect on #*this.
!*/
void deallocate_array (
T* item
);
/*!
requires
- item == is a pointer to memory that was obtained from a call to
allocate_array(). (i.e. The pointer you are deallocating must have
come from the same implementation of memory_manager_stateless
that is trying to deallocate it.)
- the memory pointed to by item hasn't already been deallocated.
ensures
- deallocates the array pointed to by item
!*/
void swap (
memory_manager_stateless& item
);
/*!
ensures
- this function has no effect on *this or item. It is just provided
to make this object's interface more compatable with the other
memory managers.
!*/
private:
// restricted functions
memory_manager_stateless(memory_manager_stateless&); // copy constructor
memory_manager_stateless& operator=(memory_manager_stateless&); // assignment operator
};
template <
typename T
>
inline void swap (
memory_manager_stateless<T>& a,
memory_manager_stateless<T>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
}
#endif // DLIB_MEMORY_MANAGER_STATELESs_ABSTRACT_
|