CXXR (C++ R)
GCManager.hpp
Go to the documentation of this file.
1 /*CXXR $Id: GCManager.hpp 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
20  * Copyright (C) 1999-2006 The R Development Core Team.
21  *
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation; either version 2.1 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program; if not, a copy is available at
34  * http://www.r-project.org/Licenses/
35  */
36 
44 #ifndef GCMANAGER_HPP
45 #define GCMANAGER_HPP
46 
47 #include <cstddef>
48 #include <iosfwd>
49 
50 namespace CXXR {
62  class GCManager {
63  public:
69  static void gc();
70 
81  static size_t maxBytes() {return s_max_bytes;}
82 
97  static size_t maxNodes() {return s_max_nodes;}
98 
106  static void resetMaxTallies();
107 
119  static void setGCThreshold(size_t initial_threshold);
120 
133  static void setMonitors(void (*pre_gc)() = 0,
134  void (*post_gc)() = 0)
135  {
136  s_pre_gc = pre_gc;
137  s_post_gc = post_gc;
138  }
139 
147  static std::ostream* setReporting(std::ostream* os = 0);
148 
156  static void torture(bool on) {}
157 
167  static size_t triggerLevel() {return s_threshold;}
168  private:
169  friend class GCNode;
170 
171  static size_t s_threshold;
172  static size_t s_min_threshold;
173 
174  static size_t s_max_bytes;
175  static size_t s_max_nodes;
176 
177  static std::ostream* s_os; // Pointer to output stream for GC
178  // reporting, or NULL.
179 
180  // Not implemented. Declared to stop the compiler generating
181  // a constructor.
182  GCManager();
183 
184  // Clean up static data associated with garbage collection.
185  static void cleanup() {}
186 
187  // Callbacks e.g. for timing:
188  static void (*s_pre_gc)();
189  static void (*s_post_gc)();
190 
191  // Detailed control of the garbage collection is carried out
192  // here.
193  static void gcController();
194 
195  // Initialize static data associated with garbage collection.
196  static void initialize();
197  };
198 } // namespace CXXR
199 
200 #endif /* GCMANAGER_HPP */