asio C++ library

PrevUpHomeNext

asio_handler_allocate

Default allocation function for handlers.

void * asio_handler_allocate(
    std::size_t size,
    ... );

Asynchronous operations may need to allocate temporary objects. Since asynchronous operations have a handler function object, these temporary objects can be said to be associated with the handler.

Implement asio_handler_allocate and asio_handler_deallocate for your own handlers to provide custom allocation for these temporary objects.

The default implementation of these allocation hooks uses operator new and operator delete.

Remarks

All temporary objects associated with a handler will be deallocated before the upcall to the handler is performed. This allows the same memory to be reused for a subsequent asynchronous operation initiated by the handler.

Example
class my_handler;

void* asio_handler_allocate(std::size_t size, my_handler* context)
{
  return ::operator new(size);
}

void asio_handler_deallocate(void* pointer, std::size_t size,
    my_handler* context)
{
  ::operator delete(pointer);
}
Requirements

Header: asio/handler_alloc_hook.hpp

Convenience header: asio.hpp


PrevUpHomeNext