memory_limiter.h

Go to the documentation of this file.
00001 #ifndef MEMORY_LIMITER_CLASS
00002 #define MEMORY_LIMITER_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : memory_limiter                                                    *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "data_structure_dll.h"
00019 
00020 #include <basis/object_base.h>
00021 
00022 // forward.
00023 class ml_memory_record;
00024 class ml_memory_state_meter;
00025 
00027 
00033 class DATA_STRUCTURE_CLASS_STYLE memory_limiter
00034 {
00035 public:
00036   memory_limiter(int overall_limit, int individual_limit);
00038 
00048   virtual ~memory_limiter();
00049 
00050   IMPLEMENT_CLASS_NAME("memory_limiter");
00051 
00052   int overall_limit() const { return _overall_limit; }
00054   int individual_limit() const { return _individual_limit; }
00056 
00057   int overall_usage() const { return _overall_size; }
00059 
00060   int overall_space_left() const { return overall_limit() - overall_usage(); }
00062 
00063   int individual_usage(int individual) const;
00065 
00066   int individual_space_left(int individual) const;
00068 
00069   istring text_form(int indent = 0) const;
00071 
00073   bool okay_allocation(int individual, int memory_desired);
00075 
00079   bool record_deletion(int individual, int memory_deleted);
00081 
00089   void reset();
00091 
00092   const int_set &individuals_listed() const;
00094 
00101 private:
00102   int _overall_limit;  
00103   int _individual_limit;  
00104   int _overall_size;  
00105   ml_memory_state_meter *_individual_sizes;  
00106 
00107   ml_memory_record *find_individual(int individual) const;
00109 };
00110 
00111 #endif
00112 

Generated on Fri Nov 28 04:29:12 2008 for HOOPLE Libraries by  doxygen 1.5.1