Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.
C++ Boost

User Allocators

Introduction

Pool objects need to request memory blocks from the system, which the Pool then splits into chunks to allocate to the user. By specifying a UserAllocator template parameter to various Pool interfaces, users can control how those system memory blocks are allocated.

Semantics

Symbol Table
SymbolMeaning
UserAllocatorA User Allocator type
blockvalue of type char *
nvalue of type UserAllocator::size_type

Typedefs
ExpressionType
UserAllocator::size_typeAn unsigned integral type that can represent the size of the largest object to be allocated
UserAllocator::difference_typeA signed integral type that can represent the difference of any two pointers

Allocation and Deallocation
ExpressionReturn TypePre-Condition/Notes
UserAllocator::malloc(n)char *Attempts to allocate n bytes from the system. Returns 0 if out-of-memory.
UserAllocator::free(block)voidblock must have been previously returned from a call to UserAllocator::malloc.

Provided Implementations

There are two UserAllocator classes provided. Both of them are in pool.hpp (see pool). The default value for the template parameter UserAllocator is always default_user_allocator_new_delete.

Synopsis

struct default_user_allocator_new_delete
{
  typedef std::size_t size_type;
  typedef std::ptrdiff_t difference_type;

  static char * malloc(const size_type bytes)
  { return new (std::nothrow) char[bytes]; }
  static void free(char * const block)
  { delete [] block; }
};

struct default_user_allocator_malloc_free
{
  typedef std::size_t size_type;
  typedef std::ptrdiff_t difference_type;

  static char * malloc(const size_type bytes)
  { return reinterpret_cast<char *>(std::malloc(bytes)); }
  static void free(char * const block)
  { std::free(block); }
};


Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)

This file can be redistributed and/or modified under the terms found in copyright.html

This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.