DDD  1.9.0.20240425101308
MemoryManager.h
Go to the documentation of this file.
1 /****************************************************************************/
2 /* */
3 /* This file is part of libDDD, a library for manipulation of DDD and SDD. */
4 /* */
5 /* Copyright (C) 2001-2008 Yann Thierry-Mieg, Jean-Michel Couvreur */
6 /* and Denis Poitrenaud */
7 /* */
8 /* This program is free software; you can redistribute it and/or modify */
9 /* it under the terms of the GNU Lesser General Public License as */
10 /* published by the Free Software Foundation; either version 3 of the */
11 /* License, or (at your option) any later version. */
12 /* This program is distributed in the hope that it will be useful, */
13 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
15 /* GNU LEsserGeneral Public License for more details. */
16 /* */
17 /* You should have received a copy of the GNU Lesser General Public License */
18 /* along with this program; if not, write to the Free Software */
19 /*Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20 /* */
21 /****************************************************************************/
22 
23 /* -*- C++ -*- */
24 #ifndef MEMORYMANAGER_H
25 #define MEMORYMANAGER_H
26 #include "ddd/DDD.h"
27 #include "ddd/DED.h"
28 #include "ddd/Hom.h"
29 #include "ddd/SDD.h"
30 #include "ddd/SDED.h"
31 #include "ddd/SHom.h"
32 #include "ddd/MLHom.h"
33 #include "ddd/IntDataSet.h"
34 
35 
36 #include "ddd/process.hpp"
37 
38 
39 class GCHook {
40  public:
41  virtual ~GCHook() {}
42  virtual void preGarbageCollect() =0;
43  virtual void postGarbageCollect() = 0;
44 
45 };
46 
53  typedef std::vector<GCHook*> hooks_t;
54  typedef hooks_t::iterator hooks_it;
55  // actually defined in DDD.cpp, bottom of file.
56  static hooks_t hooks_;
57 public:
58  /* Mesure*/
60  static unsigned int nbDDD(){return GDDD::statistics();};
62  static unsigned int nbDED(){return DED::statistics();};
64  static unsigned int nbHom(){return GHom::statistics();};
66  static unsigned int nbSDD(){return GSDD::statistics();};
68  static unsigned int nbSDED(){return SDED::statistics();};
70  static unsigned int nbShom(){return GShom::statistics();};
71  /* Garbage Collector */
74  static void mark(const GDDD &g){g.mark();};
77  static void mark(const GHom &h){h.mark();};
78 
80  static bool should_garbage() {
81  // trigger at rougly 5 million objects =1 Gig RAM
82  //return nbDED() + nbSDED() + nbShom() + nbSDD() > 3000000;
83  size_t mem = process::getResidentMemory();
84  if (mem == 0)
85  return true;
86  // add ten percent growth
87  if (mem > last_mem + last_mem / 10 ) {
88 /* std::cerr << "GC triggered at mem=" << mem << std::endl; */
89  last_mem = mem;
90  return true;
91  } else {
92 /* std::cerr << "GC not triggered mem=" << mem << std::endl; */
93  return false;
94  }
95  }
96 
100  static void garbage(){
101  for (hooks_it it = hooks_.begin(); it != hooks_.end() ; ++it) {
102  (*it)->preGarbageCollect();
103  }
104 
105  MLHom::garbage();
106  // FIXME : if you dont use SDD suppress the following
107  SDED::garbage();
108  GShom::garbage();
109  GSDD::garbage();
110  // clear the IntDataSet
112  // END FIXME
113  DED::garbage();
114  GHom::garbage();
115  GDDD::garbage();
116 
117  for (hooks_it it = hooks_.begin(); it != hooks_.end() ; ++it) {
118  (*it)->postGarbageCollect();
119  }
120  };
121 
123  static void pstats(bool reinit=true){
124  //cout << " Memory Usage " << MemUsage() << " %" << endl;
125 
126  // FIXME : if you dont use SDD suppress the following
127  SDED::pstats(reinit);
128  GShom::pstats(reinit);
129  GSDD::pstats(reinit);
130  // END FIXME
131 
132  DED::pstats(reinit);
133  GHom::pstats(reinit);
134  GDDD::pstats(reinit);
135  }
136 
137  static void setGCThreshold (size_t nbKbyte) {
138  last_mem = nbKbyte;
139  }
140 
141  static size_t getPeakMemory () {
142  should_garbage();
143  return last_mem;
144  }
145 
146  static void addHook (GCHook * hook) {
147  hooks_.push_back(hook);
148  }
149 
150  private :
151  // actually defined in DDD.cpp, bottom of file.
152  static size_t last_mem;
153 
154 
155 };
156 #endif
Definition: MemoryManager.h:39
virtual ~GCHook()
Definition: MemoryManager.h:41
virtual void postGarbageCollect()=0
virtual void preGarbageCollect()=0
This class is the base class representing a Data Decision Diagram.
Definition: DDD.h:49
void mark() const
For garbage collection internals.
Definition: DDD.cpp:308
static unsigned int statistics()
Returns unicity table current size. Gives the number of different nodes created and not yet destroyed...
Definition: DDD.cpp:303
static void garbage()
For garbage collection, do not call this directly, use MemoryManager::garbage() instead.
Definition: DDD.cpp:498
static void pstats(bool reinit=true)
Prints some statistics to std::cout.
Definition: DDD.cpp:318
This class is the base class representing a homomorphism over DDD.
Definition: Hom.h:55
static void pstats(bool reinit=true)
Prints some statistics to std::cout.
Definition: Hom.cpp:2452
static void garbage()
For garbage collection.
Definition: Hom.cpp:2023
static unsigned int statistics()
Returns unicity table current size. Gives the number of different _GHom created and not yet destroyed...
Definition: Hom.cpp:2011
void mark() const
For garbage collection internals. Marks a GHom as in use in garbage collection phase.
Definition: Hom.cpp:2016
static unsigned int statistics()
Returns unicity table current size. Gives the number of different nodes created and not yet destroyed...
Definition: SDD.cpp:255
static void pstats(bool reinit=true)
Prints some statistics to std::cout.
Definition: SDD.cpp:281
static void garbage()
For garbage collection, do not call this directly, use MemoryManager::garbage() instead.
Definition: SDD.cpp:558
static unsigned int statistics()
Return the current size of the unicity table for GShom.
Definition: SHom.cpp:2696
static void garbage()
Collects and destroys unused homomorphisms.
Definition: SHom.cpp:2716
static void pstats(bool reinit=true)
Print some usage statistics on Shom.
Definition: SHom.cpp:3336
static void garbage()
Definition: IntDataSet.cpp:35
static void garbage()
Collects and destroys unused homomorphisms.
Definition: MLHom.cpp:286
This class defines a few utility functions common to DDD.
Definition: MemoryManager.h:52
static unsigned int nbHom()
Returns the size of the unicity table for DDD Homomorphisms.
Definition: MemoryManager.h:64
static void addHook(GCHook *hook)
Definition: MemoryManager.h:146
static unsigned int nbSDED()
Returns the size of the cache unicity table for SDD.
Definition: MemoryManager.h:68
static void setGCThreshold(size_t nbKbyte)
Definition: MemoryManager.h:137
static void garbage()
Garbage collection function.
Definition: MemoryManager.h:100
static hooks_t hooks_
Definition: MemoryManager.h:56
static size_t last_mem
Definition: MemoryManager.h:152
static bool should_garbage()
tester for memory management routine triggering in a top level fixpoint
Definition: MemoryManager.h:80
static unsigned int nbSDD()
Returns the size of the unicity table for SDD.
Definition: MemoryManager.h:66
static unsigned int nbShom()
Returns the size of the unicity table for SDD Homomorphisms.
Definition: MemoryManager.h:70
static void mark(const GHom &h)
Convenience function to mark a Hom as non collectible.
Definition: MemoryManager.h:77
static size_t getPeakMemory()
Definition: MemoryManager.h:141
static void pstats(bool reinit=true)
Prints some statistics about use of unicity tables, also reinitializes peak sizes.
Definition: MemoryManager.h:123
static void mark(const GDDD &g)
Convenience function to mark a node as non collectible.
Definition: MemoryManager.h:74
static unsigned int nbDED()
Returns the size of the cache unicity table for DDD.
Definition: MemoryManager.h:62
std::vector< GCHook * > hooks_t
Definition: MemoryManager.h:53
hooks_t::iterator hooks_it
Definition: MemoryManager.h:54
static unsigned int nbDDD()
Returns the size of the unicity table for DDD.
Definition: MemoryManager.h:60
void garbage()
Definition: DED.cpp:620
unsigned int statistics()
Definition: DED.cpp:573
void pstats(bool reinit=true)
Definition: DED.cpp:577
void pstats(bool reinit=true)
Definition: SDED.cpp:673
unsigned int statistics()
Definition: SDED.cpp:668
void garbage()
Definition: SDED.cpp:694
size_t getResidentMemory()
in Bytes
Definition: process.cpp:120

Please comment this page and report errors about it on the RefDocComments page.
Generated on Thu Apr 25 2024 10:15:16 for DDD by doxygen 1.9.1