freelist.h

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2001-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Fri Jul 20 07:54:29 2001
00010 // commit: $Id: freelist.h 10095 2007-08-07 19:07:44Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/rutz/freelist.h $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_RUTZ_FREELIST_H_UTC20050626084020_DEFINED
00035 #define GROOVX_RUTZ_FREELIST_H_UTC20050626084020_DEFINED
00036 
00037 #include <cstddef>
00038 
00039 namespace rutz
00040 {
00041   class free_list_base;
00042   template <class T> class free_list;
00043 }
00044 
00046 class rutz::free_list_base
00047 {
00048 private:
00050   struct node
00051   {
00052     node* next;
00053   };
00054 
00055   node* m_node_list;
00056   std::size_t m_num_allocations;
00057   const std::size_t m_size_check;
00058 
00059   free_list_base(const free_list_base&);
00060   free_list_base& operator=(const free_list_base&);
00061 
00062 public:
00064 
00065   free_list_base(std::size_t size_check);
00066 
00068 
00071   void* allocate(std::size_t bytes);
00072 
00074   void deallocate(void* space);
00075 
00077   void release_free_nodes();
00078 
00080   std::size_t alloc_size() const { return m_size_check; }
00081 
00083   std::size_t num_allocations() const { return m_num_allocations; }
00084 };
00085 
00087 template <class T>
00088 class rutz::free_list
00089 {
00090 private:
00091   rutz::free_list_base m_base;
00092 
00093 public:
00095 
00096   free_list() : m_base(sizeof(T)) {}
00097 
00098   void* allocate(std::size_t bytes)
00099   {
00100     return m_base.allocate(bytes);
00101   }
00102 
00103   void deallocate(void* space)
00104   {
00105     m_base.deallocate(space);
00106   }
00107 
00109   void release_free_nodes() { m_base.release_free_nodes(); }
00110 };
00111 
00112 static const char __attribute__((used)) vcid_groovx_rutz_freelist_h_utc20050626084020[] = "$Id: freelist.h 10095 2007-08-07 19:07:44Z rjpeters $ $HeadURL: file:
00113 #endif // !GROOVX_RUTZ_FREELIST_H_UTC20050626084020_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:40 2008 by Doxygen version 1.5.5.