Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

slaballoc.h

Go to the documentation of this file.
00001 // See the end of this file for license information.
00002 
00003 #ifndef TORSION_SLAB_H
00004 #define TORSION_SLAB_H
00005 
00006 #include "pagespan.h"
00007 #include "list.h"
00008 
00013 
00014 class Slab_object : public List_node {
00015 };
00016 
00019 
00020 class Slab : public List_node {
00021 public:
00022   Page* page;       
00023   unsigned allocated_count;   
00024   List<Slab_object> free_list;    
00025 };
00026 
00029 
00030 class Slab_allocator {
00031 protected:
00032   unsigned object_size;     
00033   Slab* current_slab;     
00034   List<Slab> free_slabs;    
00035   List<Slab> used_slabs;    
00036   bool physical;      
00037   
00039   Slab*
00040   find_slab_with_free_object();
00041 
00043   Slab*
00044   alloc_slab();
00045   
00046 public:
00049   void
00050   init(unsigned size, bool physical_memory = false);
00051 
00053   void*
00054   alloc();
00055 
00057   void
00058   free(void* object);
00059 
00061   void
00062   clear();
00063 
00065   unsigned
00066   flush();
00067 
00068   inline unsigned
00069   get_object_size() const {
00070     return object_size;
00071   }
00072 
00073   inline void
00074   touch() {
00075     used_slabs.size();
00076   }
00077 };
00078 
00079 #endif
00080 
00081 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman
00082  *
00083  * This program is free software; you can redistribute it and/or modify it
00084  * under the terms of the GNU General Public License as published by the
00085  * Free Software Foundation; either version 2 of the License, or (at your
00086  * option) any later version.
00087  * 
00088  * This program is distributed in the hope that it will be useful, but
00089  * WITHOUT ANY WARRANTY; without even the implied warranty of
00090  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00091  * General Public License for more details (in the COPYING file).
00092  * 
00093  * You should have received a copy of the GNU General Public License along
00094  * with this program; if not, write to the Free Software Foundation, Inc.,
00095  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00096  */

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman