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

Simple Segregated Storage Implementation

Dependencies

Includes the system headers <cstddef> and <functional>.

Protected Interface

Synopsis

template <typename SizeType = std::size_t>
class simple_segregated_storage
{
  ... // Public interface

  protected:
    void * first;
    static void * & nextof(void * const ptr);
    void * find_prev(void * ptr);
};

void * first;

This data member is the free list. It points to the first chunk in the free list, or is equal to 0 if the free list is empty.

static void * & nextof(void * const ptr);

This is a convenience function. It helps clean up code dealing with the free list by making it more readable. The return value is just *ptr cast to the appropriate type. ptr must not be 0.

As an example, let us assume that we want to truncate the free list after the first chunk. That is, we want to set *first to 0; this will result in a free list with only one entry. The normal way to do this is to first cast first to a pointer to a pointer to void, and then dereference and assign (*static_cast<void **>(first) = 0;). This can be done more easily through the use of this convenience function (nextof(first) = 0;).

void * find_prev(void * ptr);

Traverses the free list referred to by first, and returns the pointer previous to where ptr would go if it was in the free list. Returns 0 if ptr would go at the beginning of the free list (i.e., before first).

Note that this function finds the location previous to where ptr would go if it was in the free list. It does not find the entry in the free list before ptr (unless ptr is already in the free list). Specifically, find_prev(0) will return 0, not the last entry in the free list.

Interface Description


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.