-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdag-alloc.h
135 lines (120 loc) · 4.17 KB
/
dag-alloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* PET
* Platform for Experimentation with efficient HPSG processing Techniques
* (C) 1999 - 2002 Ulrich Callmeier [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** \file dag-alloc.h
* memory allocation for dags
*/
#ifndef _DAG_ALLOC_H_
#define _DAG_ALLOC_H_
#include "dag.h"
#include "chunk-alloc.h"
/** An allocation marker to do stack based allocation/deallocation of whole
* memory areas.
* \see chunk_alloc_state
*/
struct dag_alloc_state
{
struct chunk_alloc_state state;
};
/** @name Memory usage statistics
* These functions are used to estimate PET's memory usage.
*/
/*@{*/
/**
* Reports how much memory (in bytes) is required for storing all permanent
* or temporary dags that have been created so far (as if memory was not
* reused). The value can be reset by dag_alloc_clear_stats().
* \todo is documentation this correct??
*/
long long dag_alloc_dynamic_mem();
/**
* Reports how much memory (in bytes) is currently allocated for storing
* temporary dags. The value can be reset by dag_alloc_clear_stats(), which
* has only a visible effect if allocated memory may shrink.
* \todo is documentation this correct??
*/
long long dag_alloc_static_mem();
/** Reset the statistics of static and dynamic memory usage */
void dag_alloc_clear_stats();
/*@}*/
/** Tell the allocator to release memory if it is convenient */
void dag_alloc_may_shrink();
/** Release all memory allocated for dags */
void dag_alloc_reset();
/** Statistics about allocated nodes */
extern int allocated_nodes;
/** Statistics about allocated arcs */
extern int allocated_arcs;
/** @name Temporary dag storage
* This is storage that is allocated for dags during parsing. At the beginning
* of a series of unifications, an allocation mark is acquired. Then, a number
* of dynamically allocated dag arcs and nodes is created during
* unification. If unification fails at some point, the memory up to the last
* mark is released. Otherwise, copying the feature structure requests more
* memory.
*/
/*@{*/
/** Allocate a dag node in temporary storage */
inline struct dag_node *dag_alloc_node()
{
allocated_nodes++;
return (dag_node *) t_alloc.allocate(sizeof(dag_node));
}
/** Allocate a dag arc in temporary storage */
inline struct dag_arc *dag_alloc_arc()
{
allocated_arcs++;
return (dag_arc *) t_alloc.allocate(sizeof(dag_arc));
}
/** Acquire an allocation marker in \a s to be able to release a bunch of
* useless memory in one step.
*/
inline void dag_alloc_mark(struct dag_alloc_state &s)
{
t_alloc.mark(s.state);
}
/** Release all memory up the mark given by \a s */
inline void dag_alloc_release(struct dag_alloc_state &s)
{
t_alloc.release(s.state);
}
/*@}*/
/** @name Permanent dag storage
* This is memory allocated during initialization of the grammar. The dags in
* this memory belong to the data base. They will only be released when the
* grammar as a whole is released, which is typically at the end of the process
*/
/*@{*/
/** Allocate a dag node in permanent storage */
inline struct dag_node *dag_alloc_p_node()
{
allocated_nodes++;
return (dag_node *) p_alloc.allocate(sizeof(dag_node));
}
/** Allocate a dag arc in permanent storage */
inline struct dag_arc *dag_alloc_p_arc()
{
allocated_arcs++;
return (dag_arc *) p_alloc.allocate(sizeof(dag_arc));
}
/** Allocate \a n dag nodes in permanent storage */
struct dag_node *dag_alloc_p_nodes(int n);
/** Allocate \a n dag arcs in permanent storage */
struct dag_arc *dag_alloc_p_arcs(int n);
/*@}*/
#endif