1 /* ///////////////////////////////////////////////////////////////////////
2 * File: process_heap_allocator.h
7 * Brief: process_heap_allocator class
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_PLATFORM_WIN_MEMORY_PROCESS_HEAP_ALLOCATOR_H
13 #define EXTL_PLATFORM_WIN_MEMORY_PROCESS_HEAP_ALLOCATOR_H
15 /*!\file process_heap_allocator.h
16 * \brief process_heap_allocator class
19 # error process_heap_allocator.h need be supported by c++.
22 /* ///////////////////////////////////////////////////////////////////////
25 #include "extl/memory/allocator_base.h"
26 #include "process_heap.h"
27 /* ///////////////////////////////////////////////////////////////////////
28 * ::extl::platform::win namespace
30 EXTL_WIN_BEGIN_WHOLE_NAMESPACE
32 /*!\brief process_heap_allocator class
33 * \param T The value type
34 * \ingroup extl_group_memory
36 template < typename_param_k T
>
37 class process_heap_allocator
: public allocator_base
< T
, process_heap_allocator
<T
> >
42 typedef process_heap_allocator
< T
> class_type
;
43 typedef allocator_base
< T
, class_type
> base_type
;
44 typedef typename_type_k
base_type::value_type value_type
;
45 typedef typename_type_k
base_type::pointer pointer
;
46 typedef typename_type_k
base_type::const_pointer const_pointer
;
47 typedef typename_type_k
base_type::reference reference
;
48 typedef typename_type_k
base_type::const_reference const_reference
;
49 typedef typename_type_k
base_type::size_type size_type
;
50 typedef typename_type_k
process_heap::handle_type handle_type
;
55 #ifdef EXTL_MEMORY_ALLOCATOR_REBIND_SUPPORT
56 template <typename_param_k U
>
59 typedef process_heap_allocator
< U
> other_type
;
65 struct deleter
: process_heap
68 typedef process_heap base_type
;
69 typedef deleter class_type
;
70 typedef typename_type_k
process_heap::handle_type handle_type
;
73 void operator()(pointer p
)
77 base_type::deallocate(p
);
83 typedef deleter deleter_type
;
88 process_heap_allocator() EXTL_THROW_0()
91 #ifdef EXTL_MEMORY_ALLOCATOR_REBIND_SUPPORT
92 template <typename_param_k U
>
93 process_heap_allocator(process_heap_allocator
< U
> const&)
96 process_heap_allocator(class_type
const&)
102 friend class allocator_base
< T
, class_type
>;
106 void* do_allocate(size_type n
, void const* hint
)
108 EXTL_SUPPRESS_UNUSED(hint
);
109 return m_process_heap
.allocate(n
* sizeof(value_type
));
111 /// Reallocates memory
112 void* do_reallocate(void* p
, size_type n
, void const* hint
)
114 EXTL_SUPPRESS_UNUSED(hint
);
115 return m_process_heap
.reallocate(p
, n
* sizeof(value_type
));
117 /// Deallocates memory
118 void do_deallocate(void* p
, size_type n
)
120 EXTL_SUPPRESS_UNUSED(n
);
121 m_process_heap
.deallocate(p
);
123 /// Deallocates memory
124 void do_deallocate(void* p
)
126 m_process_heap
.deallocate(p
);
130 process_heap m_process_heap
; //!< The process heap
134 /* ///////////////////////////////////////////////////////////////////////
135 * void specialization
137 EXTL_TEMPLATE_SPECIALISATION
138 class process_heap_allocator
< void >
141 typedef process_heap_allocator
< void > class_type
;
142 typedef void value_type
;
143 typedef void* pointer
;
144 typedef void const* const_pointer
;
145 typedef e_size_t size_type
;
148 #ifdef EXTL_MEMORY_ALLOCATOR_REBIND_SUPPORT
149 template <typename_param_k U
>
152 typedef process_heap_allocator
< U
> other_type
;
157 struct deleter
: process_heap
160 typedef process_heap base_type
;
161 typedef deleter class_type
;
162 typedef process_heap::handle_type handle_type
;
165 void operator()(pointer p
)
169 base_type::deallocate(p
);
174 typedef deleter deleter_type
;
177 void* do_allocate(size_type n
, void const* hint
);
178 void* do_reallocate(void* p
, size_type n
, void const* hint
);
179 void do_deallocate(void* p
, size_type n
);
180 void do_deallocate(void* p
);
183 /* //////////////////////////////////////////////////////////////////// */
184 template < typename_param_k T
>
185 inline e_bool_t
operator ==(process_heap_allocator
<T
> const&, process_heap_allocator
<T
> const &)
190 template < typename_param_k T
>
191 inline e_bool_t
operator !=(process_heap_allocator
<T
> const &, process_heap_allocator
<T
> const &)
195 /* ///////////////////////////////////////////////////////////////////////
198 #ifdef EXTL_MEMORY_ALLOCATOR_TEST_ENABLE
199 # include "unit_test/process_heap_allocator_test.h"
202 /* ///////////////////////////////////////////////////////////////////////
203 * ::extl::platform::win namespace
205 EXTL_WIN_END_WHOLE_NAMESPACE
207 /* //////////////////////////////////////////////////////////////////// */
208 #endif /* EXTL_PLATFORM_WIN_MEMORY_PROCESS_HEAP_ALLOCATOR_H */
209 /* //////////////////////////////////////////////////////////////////// */