Use hook allocation strategy whenever associated allocator is std::allocator.

This commit is contained in:
Christopher Kohlhoff 2017-07-29 20:00:30 +10:00
parent 5b4aa5ef9b
commit c2cb5395ec

View File

@ -121,17 +121,34 @@ public:
Handler& handler_; Handler& handler_;
}; };
template <typename Handler, typename Allocator>
struct get_hook_allocator
{
typedef Allocator type;
static type get(Handler&, const Allocator& a)
{
return a;
}
};
template <typename Handler, typename T>
struct get_hook_allocator<Handler, std::allocator<T> >
{
typedef hook_allocator<Handler, T> type;
static type get(Handler& handler, const std::allocator<T>&)
{
return type(handler);
}
};
} // namespace detail } // namespace detail
} // namespace asio } // namespace asio
#define ASIO_DEFINE_HANDLER_PTR(op) \ #define ASIO_DEFINE_HANDLER_PTR(op) \
struct ptr \ struct ptr \
{ \ { \
typedef typename ::asio::associated_allocator<Handler, \
::asio::detail::hook_allocator<Handler, \
void> >::type associated_allocator_type; \
typedef ASIO_REBIND_ALLOC( \
associated_allocator_type, op) allocator_type; \
Handler* h; \ Handler* h; \
op* v; \ op* v; \
op* p; \ op* p; \
@ -141,16 +158,26 @@ public:
} \ } \
static op* allocate(Handler& handler) \ static op* allocate(Handler& handler) \
{ \ { \
allocator_type a(::asio::associated_allocator<Handler, \ typedef typename ::asio::associated_allocator< \
::asio::detail::hook_allocator<Handler, void> >::get(handler, \ Handler>::type associated_allocator_type; \
::asio::detail::hook_allocator<Handler, void>(handler))); \ typedef typename ::asio::detail::get_hook_allocator< \
Handler, associated_allocator_type>::type hook_allocator_type; \
ASIO_REBIND_ALLOC(hook_allocator_type, op) a( \
::asio::detail::get_hook_allocator< \
Handler, associated_allocator_type>::get( \
handler, ::asio::get_associated_allocator(handler))); \
return a.allocate(1); \ return a.allocate(1); \
} \ } \
void reset() \ void reset() \
{ \ { \
allocator_type a(::asio::associated_allocator<Handler, \ typedef typename ::asio::associated_allocator< \
::asio::detail::hook_allocator<Handler, void> >::get(*h, \ Handler>::type associated_allocator_type; \
::asio::detail::hook_allocator<Handler, void>(*h))); \ typedef typename ::asio::detail::get_hook_allocator< \
Handler, associated_allocator_type>::type hook_allocator_type; \
ASIO_REBIND_ALLOC(hook_allocator_type, op) a( \
::asio::detail::get_hook_allocator< \
Handler, associated_allocator_type>::get( \
*h, ::asio::get_associated_allocator(*h))); \
if (p) \ if (p) \
{ \ { \
p->~op(); \ p->~op(); \