Realistic 3D camera system
3D camera system components
handler_alloc_helpers.hpp
Go to the documentation of this file.
1 //
2 // detail/handler_alloc_helpers.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
12 #define ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
22 
24 
25 // Calls to asio_handler_allocate and asio_handler_deallocate must be made from
26 // a namespace that does not contain any overloads of these functions. The
27 // asio_handler_alloc_helpers namespace is defined here for that purpose.
29 
30 template <typename Handler>
31 inline void* allocate(std::size_t s, Handler& h)
32 {
33 #if !defined(ASIO_HAS_HANDLER_HOOKS)
34  return ::operator new(s);
35 #else
37  return asio_handler_allocate(s, asio::detail::addressof(h));
38 #endif
39 }
40 
41 template <typename Handler>
42 inline void deallocate(void* p, std::size_t s, Handler& h)
43 {
44 #if !defined(ASIO_HAS_HANDLER_HOOKS)
45  ::operator delete(p);
46 #else
48  asio_handler_deallocate(p, s, asio::detail::addressof(h));
49 #endif
50 }
51 
52 } // namespace asio_handler_alloc_helpers
53 
54 #define ASIO_DEFINE_HANDLER_PTR(op) \
55  struct ptr \
56  { \
57  Handler* h; \
58  void* v; \
59  op* p; \
60  ~ptr() \
61  { \
62  reset(); \
63  } \
64  void reset() \
65  { \
66  if (p) \
67  { \
68  p->~op(); \
69  p = 0; \
70  } \
71  if (v) \
72  { \
73  asio_handler_alloc_helpers::deallocate(v, sizeof(op), *h); \
74  v = 0; \
75  } \
76  } \
77  } \
78 
79 
81 
82 #endif // ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
ASIO_DECL void * asio_handler_allocate(std::size_t size,...)
Default allocation function for handlers.
ASIO_DECL void asio_handler_deallocate(void *pointer, std::size_t size,...)
Default deallocation function for handlers.
void asio_handler_deallocate(void *pointer, std::size_t size, binder1< Handler, Arg1 > *this_handler)
SocketService & s
Definition: connect.hpp:521
void * asio_handler_allocate(std::size_t size, binder1< Handler, Arg1 > *this_handler)
void deallocate(void *p, std::size_t s, Handler &h)
void * allocate(std::size_t s, Handler &h)