4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief pool_alloc_mixin public header */
26 #ifndef HH_SENF_Utils_pool_alloc_mixin_
27 #define HH_SENF_Utils_pool_alloc_mixin_ 1
30 #include <boost/pool/singleton_pool.hpp>
32 //#include "pool_alloc_mixin.mpp"
33 ///////////////////////////////hh.p////////////////////////////////////////
37 struct pool_alloc_mixin_tag;
39 /** \brief Mixin to assign pool allocator to a class
41 This mixin will overload a classes <tt>operator new</tt> and <tt>operator delete</tt> so as
42 to make the class use the <a
43 href="http://www.boost.org/libs/pool/doc/index.html">Boost.Pool</a> memory allocator by
44 default. Using this allocator does however introduce a few restrictions:
46 \li The operator is defined for a fixed size. Therefore if you derive from the class <b>you
47 must not change it's size</b>.
48 \li If you change the size of the class in a derived class you have to derive from
49 pool_alloc_mixin again.
54 : public senf::pool_alloc_mixin<SomeClass>
60 \note pool_alloc_mixin uses the <a
61 href="http://www.boost.org/libs/pool/doc/index.html">Boost.Pool</a> <i>singleton
62 pool</i> interface with the tag <tt>pool_alloc_mixin_tag</tt>. This class is accessible
63 via the <tt>pool</tt> member. Using this member, it is simple to call relevant pool
64 functions, e.g. <tt>SomeClass::pool<>::release_memory()</tt>.
67 class pool_alloc_mixin
70 /** \brief Templated typedef for the pool used
72 Since the instantiation of the typedef must be delayed until Self is completely defined,
73 the simple typedef is replaced with a nested struct.
75 template <class T=void>
77 : public boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) >
79 typedef boost::singleton_pool< pool_alloc_mixin_tag, sizeof(Self) > type;
82 static void * operator new (size_t size);
83 ///< Operator new utilizing pool allocation
84 static void operator delete (void *p, size_t size);
85 ///< Operator delete utilizing pool allocation
88 static unsigned long allocCounter();
90 static unsigned long allocCounter(long delta);
96 ///////////////////////////////hh.e////////////////////////////////////////
97 //#include "pool_alloc_mixin.cci"
98 //#include "pool_alloc_mixin.ct"
99 #include "pool_alloc_mixin.cti"
106 // c-file-style: "senf"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "scons -u test"
110 // comment-column: 40