~ubuntu-branches/ubuntu/jaunty/asio/jaunty

« back to all changes in this revision

Viewing changes to include/asio/handler_alloc_hook.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Simon Richter
  • Date: 2007-09-07 11:10:41 UTC
  • Revision ID: james.westby@ubuntu.com-20070907111041-f0uwhs0llvzj9ah5
Tags: upstream-0.3.8~rc3
ImportĀ upstreamĀ versionĀ 0.3.8~rc3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// handler_alloc_hook.hpp
 
3
// ~~~~~~~~~~~~~~~~~~~~~~
 
4
//
 
5
// Copyright (c) 2003-2007 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_HANDLER_ALLOC_HOOK_HPP
 
12
#define ASIO_HANDLER_ALLOC_HOOK_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/push_options.hpp"
 
19
 
 
20
#include "asio/detail/push_options.hpp"
 
21
#include <cstddef>
 
22
#include <boost/config.hpp>
 
23
#include "asio/detail/pop_options.hpp"
 
24
 
 
25
namespace asio {
 
26
 
 
27
/// Default allocation function for handlers.
 
28
/**
 
29
 * Asynchronous operations may need to allocate temporary objects. Since
 
30
 * asynchronous operations have a handler function object, these temporary
 
31
 * objects can be said to be associated with the handler.
 
32
 *
 
33
 * Implement asio_handler_allocate and asio_handler_deallocate for your own
 
34
 * handlers to provide custom allocation for these temporary objects.
 
35
 *
 
36
 * This default implementation is simply:
 
37
 * @code
 
38
 * return ::operator new(bytes);
 
39
 * @endcode
 
40
 *
 
41
 * @note All temporary objects associated with a handler will be deallocated
 
42
 * before the upcall to the handler is performed. This allows the same memory to
 
43
 * be reused for a subsequent asynchronous operation initiated by the handler.
 
44
 *
 
45
 * @par Example
 
46
 * @code
 
47
 * class my_handler;
 
48
 *
 
49
 * void* asio_handler_allocate(std::size_t size, my_handler* context)
 
50
 * {
 
51
 *   return ::operator new(size);
 
52
 * }
 
53
 *
 
54
 * void asio_handler_deallocate(void* pointer, std::size_t size,
 
55
 *     my_handler* context)
 
56
 * {
 
57
 *   ::operator delete(pointer);
 
58
 * }
 
59
 * @endcode
 
60
 */
 
61
inline void* asio_handler_allocate(std::size_t size, ...)
 
62
{
 
63
  return ::operator new(size);
 
64
}
 
65
 
 
66
/// Default deallocation function for handlers.
 
67
/**
 
68
 * Implement asio_handler_allocate and asio_handler_deallocate for your own
 
69
 * handlers to provide custom allocation for the associated temporary objects.
 
70
 *
 
71
 * This default implementation is simply:
 
72
 * @code
 
73
 * ::operator delete(pointer);
 
74
 * @endcode
 
75
 *
 
76
 * @sa asio_handler_allocate.
 
77
 */
 
78
inline void asio_handler_deallocate(void* pointer, std::size_t size, ...)
 
79
{
 
80
  (void)(size);
 
81
  ::operator delete(pointer);
 
82
}
 
83
 
 
84
} // namespace asio
 
85
 
 
86
#include "asio/detail/pop_options.hpp"
 
87
 
 
88
#endif // ASIO_HANDLER_ALLOC_HOOK_HPP