feisty meow concerns codebase  2.140
memory_limiter.h
Go to the documentation of this file.
1 #ifndef MEMORY_LIMITER_CLASS
2 #define MEMORY_LIMITER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : memory_limiter *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2001-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/contracts.h>
20 #include <structures/set.h>
21 
22 namespace structures {
23 
24 // forward.
25 class ml_memory_record;
26 class ml_memory_state_meter;
27 
29 
36 {
37 public:
40 
50  virtual ~memory_limiter();
51 
52  DEFINE_CLASS_NAME("memory_limiter");
53 
54  int overall_limit() const { return _overall_limit; }
56  int individual_limit() const { return _individual_limit; }
58 
59  int overall_usage() const { return _overall_size; }
61 
62  int overall_space_left() const { return overall_limit() - overall_usage(); }
64 
65  int individual_usage(int individual) const;
67 
68  int individual_space_left(int individual) const;
70 
71  basis::astring text_form(int indent = 0) const;
73 
75  bool okay_allocation(int individual, int memory_desired);
77 
81  bool record_deletion(int individual, int memory_deleted);
83 
91  void reset();
93 
96 
103 private:
104  int _overall_limit;
105  int _individual_limit;
106  int _overall_size;
107  ml_memory_state_meter *_individual_sizes;
108 
109  ml_memory_record *find_individual(int individual) const;
111 };
112 
113 } //namespace.
114 
115 #endif
116 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
A simple object that wraps a templated set of ints.
Definition: set.h:156
Tracks memory currently in use by memory manager objects.
int individual_usage(int individual) const
returns the amount of memory used by "individual".
memory_limiter(int overall_limit, int individual_limit)
creates a limiter that allows "overall_limit" bytes to be in use.
int overall_space_left() const
returns the overall space left for allocation.
DEFINE_CLASS_NAME("memory_limiter")
int overall_limit() const
returns the current overall limit.
bool okay_allocation(int individual, int memory_desired)
returns true if "individual" may allocate "memory_desired" bytes.
bool record_deletion(int individual, int memory_deleted)
acknowledges that the "individual" freed "memory_deleted" bytes.
int overall_usage() const
returns the size used by all managed memory.
int individual_limit() const
returns the current individual limit.
const structures::int_set & individuals_listed() const
reports the current set of individuals using memory.
basis::astring text_form(int indent=0) const
returns a string that lists out the overall plus individual limits.
int individual_space_left(int individual) const
returns the space left for the individual specified.
void reset()
returns the object to a pristine state.
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55