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 the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class template allocator

boost::mpi::allocator — Standard Library-compliant allocator for the MPI-2 memory allocation routines.

Synopsis

// In header: <boost/mpi/allocator.hpp>

template<typename T> 
class allocator {
public:
  // types
  typedef std::size_t    size_type;        // Holds the size of objects. 
  typedef std::ptrdiff_t difference_type;  // Holds the number of elements between two pointers. 
  typedef T *            pointer;          // A pointer to an object of type T. 
  typedef const T *      const_pointer;    // A pointer to a constant object of type T. 
  typedef T &            reference;        // A reference to an object of type T. 
  typedef const T &      const_reference;  // A reference to a constant object of type T. 
  typedef T              value_type;       // The type of memory allocated by this allocator. 

  // member classes/structs/unions

  // Retrieve the type of an allocator similar to this allocator but for a
  // different value type.
  template<typename U> 
  struct rebind {
    // types
    typedef allocator< U > other;
  };

  // construct/copy/destruct
  allocator();
  allocator(const allocator &);
  template<typename U> allocator(const allocator< U > &);
  ~allocator();

  // public member functions
  pointer address(reference) const;
  const_pointer address(const_reference) const;
  pointer allocate(size_type, allocator< void >::const_pointer = 0);
  void deallocate(pointer, size_type);
  size_type max_size() const;
  void construct(pointer, const T &);
  void destroy(pointer);
};

Description

This allocator provides a standard C++ interface to the MPI_Alloc_mem and MPI_Free_mem routines of MPI-2. It is intended to be used with the containers in the Standard Library (vector, in particular) in cases where the contents of the container will be directly transmitted via MPI. This allocator is also used internally by the library for character buffers that will be used in the transmission of data.

The allocator class template only provides MPI memory allocation when the underlying MPI implementation is either MPI-2 compliant or is known to provide MPI_Alloc_mem and MPI_Free_mem as extensions. When the MPI memory allocation routines are not available, allocator is brought in directly from namespace std, so that standard allocators are used throughout. The macro BOOST_MPI_HAS_MEMORY_ALLOCATION will be defined when the MPI-2 memory allocation facilities are available.

allocator public construct/copy/destruct

  1. allocator();

    Default-construct an allocator.

  2. allocator(const allocator &);

    Copy-construct an allocator.

  3. template<typename U> allocator(const allocator< U > &);

    Copy-construct an allocator from another allocator for a different value type.

  4. ~allocator();

    Destroy an allocator.

allocator public member functions

  1. pointer address(reference x) const;

    Returns the address of object x.

  2. const_pointer address(const_reference x) const;

    Returns the address of object x.

  3. pointer allocate(size_type n, allocator< void >::const_pointer = 0);

    Allocate enough memory for n elements of type T.

    Parameters:

    n

    The number of elements for which memory should be allocated.

    Returns:

    a pointer to the newly-allocated memory

  4. void deallocate(pointer p, size_type);

    Deallocate memory referred to by the pointer p.

    Parameters:

    p

    The pointer whose memory should be deallocated. This pointer shall have been returned from the allocate() function and not have already been freed.

  5. size_type max_size() const;

    Returns the maximum number of elements that can be allocated with allocate().

  6. void construct(pointer p, const T & val);

    Construct a copy of val at the location referenced by p.

  7. void destroy(pointer p);

    Destroy the object referenced by p.

Specializations


PrevUpHomeNext