freelist.cc

Go to the documentation of this file.
00001 /** @file rutz/freelist.cc memory allocation via a free-list pool */
00002 
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 08:00:31 2001
00010 // commit: $Id: freelist.cc 9612 2008-04-10 16:40:31Z rjpeters $
00011 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/freelist.cc $
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 //
00032 ///////////////////////////////////////////////////////////////////////
00033 
00034 #ifndef GROOVX_RUTZ_FREELIST_CC_UTC20050626084019_DEFINED
00035 #define GROOVX_RUTZ_FREELIST_CC_UTC20050626084019_DEFINED
00036 
00037 #include "rutz/freelist.h"
00038 
00039 #include "rutz/debug.h"
00040 GVX_DBG_REGISTER
00041 
00042 rutz::free_list_base::free_list_base(std::size_t size_check) :
00043   m_node_list(0), m_num_allocations(0), m_size_check(size_check)
00044 {
00045   GVX_ASSERT(m_size_check >= sizeof(node));
00046 }
00047 
00048 void* rutz::free_list_base::allocate(std::size_t bytes)
00049 {
00050   GVX_ASSERT(bytes == m_size_check);
00051   if (m_node_list == 0)
00052     {
00053       ++m_num_allocations;
00054       return ::operator new(bytes);
00055     }
00056   node* n = m_node_list;
00057   m_node_list = m_node_list->next;
00058   return static_cast<void*>(n);
00059 }
00060 
00061 void rutz::free_list_base::deallocate(void* space)
00062 {
00063   node* n = static_cast<node*>(space);
00064   n->next = m_node_list;
00065   m_node_list = n;
00066 }
00067 
00068 void rutz::free_list_base::release_free_nodes()
00069 {
00070   while (m_node_list != 0)
00071     {
00072       void* p = m_node_list;
00073       m_node_list = m_node_list->next;
00074       ::operator delete(p);
00075       --m_num_allocations;
00076     }
00077 }
00078 
00079 static const char __attribute__((used)) vcid_groovx_rutz_freelist_cc_utc20050626084019[] = "$Id: freelist.cc 9612 2008-04-10 16:40:31Z rjpeters $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/freelist.cc $";
00080 #endif // !GROOVX_RUTZ_FREELIST_CC_UTC20050626084019_DEFINED
Generated on Sun May 8 08:42:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3