blob: 4cf418d242290e309c20d3d360b84ccb1c9b9fab (
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
|
// Copyright (C) 2006 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_MEMORY_MANAGER_GLOBAl_1_
#define DLIB_MEMORY_MANAGER_GLOBAl_1_
#include "../algs.h"
#include "../memory_manager/memory_manager_kernel_abstract.h"
#include "memory_manager_global_kernel_abstract.h"
namespace dlib
{
template <
typename T,
typename factory
>
class memory_manager_global_kernel_1
{
/*!
INITIAL VALUE
- *global_mm == get_global_memory_manager()
CONVENTION
- global_mm->get_number_of_allocations() == get_number_of_allocations()
- *global_mm == get_global_memory_manager()
!*/
public:
typedef typename factory::template return_type<T>::type mm_global_type;
typedef T type;
template <typename U>
struct rebind {
typedef memory_manager_global_kernel_1<U,factory> other;
};
memory_manager_global_kernel_1(
) :
global_mm(factory::template get_instance<T>())
{}
virtual ~memory_manager_global_kernel_1(
) {}
unsigned long get_number_of_allocations (
) const { return global_mm->get_number_of_allocations(); }
mm_global_type& get_global_memory_manager (
) { return *global_mm; }
T* allocate (
)
{
return global_mm->allocate();
}
void deallocate (
T* item
)
{
global_mm->deallocate(item);
}
T* allocate_array (
unsigned long size
)
{
return global_mm->allocate_array(size);
}
void deallocate_array (
T* item
)
{
global_mm->deallocate_array(item);
}
void swap (
memory_manager_global_kernel_1& item
)
{
exchange(item.global_mm, global_mm);
}
private:
mm_global_type* global_mm;
// restricted functions
memory_manager_global_kernel_1(memory_manager_global_kernel_1&); // copy constructor
memory_manager_global_kernel_1& operator=(memory_manager_global_kernel_1&); // assignment operator
};
template <
typename T,
typename factory
>
inline void swap (
memory_manager_global_kernel_1<T,factory>& a,
memory_manager_global_kernel_1<T,factory>& b
) { a.swap(b); }
/*!
provides a global swap function
!*/
}
#endif // DLIB_MEMORY_MANAGER_GLOBAl_1_
|