From 6a65f4208f05af4cd2d76ae71c956b426d9e2373 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Thu, 12 Mar 2009 10:30:31 +0000 Subject: [PATCH] add some text to explain sentinels git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66790 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ProgrammersManual.html | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index a990462c253..e2525ae84e0 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -901,6 +901,7 @@ Related classes of interest are explained in the following subsections:
  • ilist_traits
  • iplist
  • llvm/ADT/ilist_node.h
  • +
  • Sentinels
  • @@ -944,6 +945,44 @@ in the default manner.

    ilist_node<T>.

    + +
    + Sentinels +
    + +
    +

    ilists have another speciality that must be considered. To be a good +citizen in the C++ ecosystem, it needs to support the standard container +operations, such as begin and end iterators, etc. Also, the +operator-- must work correctly on the end iterator in the +case of non-empty ilists.

    + +

    The only sensible solution to this problem is to allocate a so-called +sentinel along with the intrusive list, which serves as the end +iterator, providing the back-link to the last element. However conforming to the +C++ convention it is illegal to operator++ beyond the sentinel and it +also must not be dereferenced.

    + +

    These constraints allow for some implementation freedom to the ilist +how to allocate and store the sentinel. The corresponding policy is dictated +by ilist_traits<T>. By default a T gets heap-allocated +whenever the need for a sentinel arises.

    + +

    While the default policy is sufficient in most cases, it may break down when +T does not provide a default constructor. Also, in the case of many +instances of ilists, the memory overhead of the associated sentinels +is wasted. To alleviate the situation with numerous and voluminous +T-sentinels, sometimes a trick is employed, leading to ghostly +sentinels.

    + +

    Ghostly sentinels are obtained by specially-crafted ilist_traits<T> +which superpose the sentinel with the ilist instance in memory. Pointer +arithmetic is used to obtain the sentinel, which is relative to the +ilist's this pointer. The ilist is augmented by an +extra pointer, which serves as the back-link of the sentinel. This is the only +field in the ghostly sentinel which can be legally accessed.

    +
    +
    Other Sequential Container options -- 2.34.1