Stan
1.3
probability, sampling & optimization
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerator
Friends
Macros
Pages
src
stan
agrad
rev
var_stack.hpp
Go to the documentation of this file.
1
#ifndef __STAN__AGRAD__REV__VAR_STACK_HPP__
2
#define __STAN__AGRAD__REV__VAR_STACK_HPP__
3
4
#include <vector>
5
#include <
stan/memory/stack_alloc.hpp
>
6
7
namespace
stan {
8
namespace
agrad {
9
10
// forward declaration of chainable
11
class
chainable;
12
class
chainable_alloc;
13
14
// FIXME: manage all this as a single singleton (thread local)
15
extern
std::vector<chainable*>
var_stack_
;
16
extern
std::vector<chainable*>
var_nochain_stack_
;
17
extern
std::vector<chainable_alloc*>
var_alloc_stack_
;
18
extern
memory::stack_alloc
memalloc_
;
19
26
class
chainable_alloc
{
27
public
:
28
chainable_alloc
() {
29
var_alloc_stack_
.push_back(
this
);
30
}
31
virtual
~chainable_alloc
() { };
32
};
33
37
static
void
recover_memory
() {
38
var_stack_
.clear();
39
var_nochain_stack_
.clear();
40
for
(
size_t
i = 0; i <
var_alloc_stack_
.size(); i++)
41
delete
var_alloc_stack_
[i];
42
var_alloc_stack_
.clear();
43
memalloc_
.
recover_all
();
44
}
45
49
static
void
free_memory
() {
50
memalloc_
.
free_all
();
51
}
52
53
54
}
55
}
56
#endif
[
Stan Home Page
]
© 2011–2013, Stan Development Team.