4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief pool_alloc_mixin public header */
31 #ifndef HH_SENF_Utils_pool_alloc_mixin_
32 #define HH_SENF_Utils_pool_alloc_mixin_ 1
35 #include <boost/pool/singleton_pool.hpp>
37 //#include "pool_alloc_mixin.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 struct pool_alloc_mixin_tag;
44 /** \brief Mixin to assign pool allocator to a class
46 This mixin will overload a classes <tt>operator new</tt> and <tt>operator delete</tt> so as
47 to make the class use the <a
48 href="http://www.boost.org/doc/libs/release/libs/pool/doc/index.html">Boost.Pool</a> memory allocator by
49 default. Using this allocator does however introduce a few restrictions:
51 \li The operator is defined for a fixed size. Therefore if you derive from the class <b>you
52 must not change it's size</b>.
53 \li If you change the size of the class in a derived class you have to derive from
54 pool_alloc_mixin again.
59 : public senf::pool_alloc_mixin<SomeClass>
65 \note pool_alloc_mixin uses the <a
66 href="http://www.boost.org/doc/libs/release/libs/pool/doc/index.html">Boost.Pool</a> <i>singleton
67 pool</i> interface with the tag <tt>pool_alloc_mixin_tag</tt>. This class is accessible
68 via the <tt>pool</tt> member. Using this member, it is simple to call relevant pool
69 functions, e.g. <tt>SomeClass::pool<>::release_memory()</tt>.
72 class pool_alloc_mixin
75 /** \brief Templated typedef for the pool used
77 Since the instantiation of the typedef must be delayed until Self is completely defined,
78 the simple typedef is replaced with a nested struct.
80 template <class T=void>
82 : public boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) >
84 typedef boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) > type;
87 static void * operator new (size_t size);
88 ///< Operator new utilizing pool allocation
89 static void operator delete (void *p, size_t size);
90 ///< Operator delete utilizing pool allocation
93 static unsigned long allocCounter();
95 static unsigned long allocCounter(long delta);
101 //-/////////////////////////////////////////////////////////////////////////////////////////////////
102 //#include "pool_alloc_mixin.cci"
103 //#include "pool_alloc_mixin.ct"
104 #include "pool_alloc_mixin.cti"
111 // c-file-style: "senf"
112 // indent-tabs-mode: nil
113 // ispell-local-dictionary: "american"
114 // compile-command: "scons -u test"
115 // comment-column: 40