2 // handler_alloc_hook.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_HANDLER_ALLOC_HOOK_HPP
12 #define BOOST_ASIO_HANDLER_ALLOC_HOOK_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
21 #include <boost/asio/detail/push_options.hpp>
26 #if defined(BOOST_ASIO_NO_DEPRECATED)
28 // Places in asio that would have previously called the allocate or deallocate
29 // hooks to manage memory, now call them only to check whether the result types
30 // are these types. If the result is not the correct type, it indicates that
31 // the user code still has the old hooks in place, and if so we want to trigger
33 enum asio_handler_allocate_is_no_longer_used {};
34 enum asio_handler_deallocate_is_no_longer_used {};
36 typedef asio_handler_allocate_is_no_longer_used
37 asio_handler_allocate_is_deprecated;
38 typedef asio_handler_deallocate_is_no_longer_used
39 asio_handler_deallocate_is_deprecated;
41 #else // defined(BOOST_ASIO_NO_DEPRECATED)
43 typedef void* asio_handler_allocate_is_deprecated;
44 typedef void asio_handler_deallocate_is_deprecated;
46 #endif // defined(BOOST_ASIO_NO_DEPRECATED)
48 /// (Deprecated: Use the associated_allocator trait.) Default allocation
49 /// function for handlers.
51 * Asynchronous operations may need to allocate temporary objects. Since
52 * asynchronous operations have a handler function object, these temporary
53 * objects can be said to be associated with the handler.
55 * Implement asio_handler_allocate and asio_handler_deallocate for your own
56 * handlers to provide custom allocation for these temporary objects.
58 * The default implementation of these allocation hooks uses <tt>::operator
59 * new</tt> and <tt>::operator delete</tt>.
61 * @note All temporary objects associated with a handler will be deallocated
62 * before the upcall to the handler is performed. This allows the same memory to
63 * be reused for a subsequent asynchronous operation initiated by the handler.
69 * void* asio_handler_allocate(std::size_t size, my_handler* context)
71 * return ::operator new(size);
74 * void asio_handler_deallocate(void* pointer, std::size_t size,
75 * my_handler* context)
77 * ::operator delete(pointer);
81 BOOST_ASIO_DECL asio_handler_allocate_is_deprecated
82 asio_handler_allocate(std::size_t size, ...);
84 /// Default deallocation function for handlers.
86 * Implement asio_handler_allocate and asio_handler_deallocate for your own
87 * handlers to provide custom allocation for the associated temporary objects.
89 * The default implementation of these allocation hooks uses <tt>::operator
90 * new</tt> and <tt>::operator delete</tt>.
92 * @sa asio_handler_allocate.
94 BOOST_ASIO_DECL asio_handler_deallocate_is_deprecated
95 asio_handler_deallocate(void* pointer, std::size_t size, ...);
100 #include <boost/asio/detail/pop_options.hpp>
102 #if defined(BOOST_ASIO_HEADER_ONLY)
103 # include <boost/asio/impl/handler_alloc_hook.ipp>
104 #endif // defined(BOOST_ASIO_HEADER_ONLY)
106 #endif // BOOST_ASIO_HANDLER_ALLOC_HOOK_HPP