/[ascend]/branches/relerrorlist/ascend/compiler/freestore.h
ViewVC logotype

Contents of /branches/relerrorlist/ascend/compiler/freestore.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3234 - (show annotations) (download) (as text)
Thu Nov 2 11:26:15 2017 UTC (4 years, 8 months ago) by jpye
File MIME type: text/x-chdr
File size: 5343 byte(s)
added very simple test for the module 'freestore'.

1 /*
2 * Implementation of Free Store Module
3 * Kirk A. Abbott
4 * Created Dec 18, 1994
5 * Version: $Revision: 1.5 $
6 * Version control file: $RCSfile: freestore.h,v $
7 * Date last modified: $Date: 1998/06/16 16:36:27 $
8 * Last modified by: $Author: mthomas $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
13 *
14 * The Ascend Language Interpreter is free software; you can
15 * redistribute it and/or modify it under the terms of the GNU
16 * General Public License as published by the Free Software
17 * Foundation; either version 2 of the License, or (at your option)
18 * any later version.
19 *
20 * The Ascend Language Interpreter is distributed in hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29 /** @file
30 Implementation of Free Store Module.
31 FIXME: this module appears to be pretty poorly used in ASCEND
32 and could probably be replaced by something else like 'pool'.
33
34 Note: this file is specific to relation data structures and should
35 not be used for anything else. In fact it shouldn't even be used
36 for those because a much better tested module (pool.h) is
37 available and in use everywhere else in the compiler.
38
39 * <pre>
40 * When #including freestore.h, make sure these files are #included first:
41 * #include "utilities/ascConfig.h"
42 * #include "compiler.h"
43 * #include "stack.h"
44 * #include "exprsym.h"
45 * </pre>
46 */
47
48 #ifndef ASC_FREESTORE_H
49 #define ASC_FREESTORE_H
50
51 #include <ascend/general/platform.h>
52 #include <ascend/general/stack.h>
53 #include "relation_type.h"
54
55 /** @addtogroup compiler_rel Compiler Relations
56 @{
57 */
58
59 /** Free store data structure. */
60 struct FreeStore {
61 union RelationTermUnion **root; /**< ptr to it all */
62 union RelationTermUnion *next_free; /**< ptr to next_clean slot */
63 struct gs_stack_t *returned; /**< stack of returned blocks */
64 int n_buffers; /**< # of big chunks */
65 int buffer_length; /**< size of chunks */
66 int row; /**< index of the next free location's row */
67 int col; /**< index of the next free locations's col */
68 };
69
70 extern long FreeStore_UnitsAllocated();
71 /**< Retrieve the number of free store units allocated. */
72 ASC_DLLSPEC void FreeStore__Statistics(FILE *fp, struct FreeStore *store);
73 /**< Print stats about the free store to fp. */
74
75 ASC_DLLSPEC void FreeStore__BlastMem(struct FreeStore *store);
76 /**<
77 * This function deallocates *all* the memory associated with a free
78 * store. The free store should not be referenced after this call.
79 */
80
81 /*
82 * These are the normal user level routines.
83 *
84 * Known Bugs:
85 * The blocks returned the user are never anything but the size of
86 * a relation token. This is not highly reuseable.
87 *
88 * Features?:
89 * This module runs a stack of free_stores, which is sometimes
90 * handy, to avoid passing around a free_store pointer. Note,
91 * however, that it costs just as much to dereference the global
92 * variables as it does to pass the store pointer.
93 */
94
95 ASC_DLLSPEC struct FreeStore *FreeStore_Create(int n_buffers, int buffer_length);
96 /**<
97 * Create a new free store with 1 buffer of size buffer length.
98 * The information within the buffer is *not* initialized in any way.
99 */
100
101 extern void FreeStore_ReInit(struct FreeStore *store);
102 /**<
103 * Reinitializes the free store. This simply tells the free store to
104 * *forget* about anything that may have be allotted to a user. In other
105 * words, after this call the freestore will behave as if it was just
106 * created. Any information that a user wants, had better be copied before
107 * this call, as it is now a candidate to be allotted to someone else.
108 */
109
110 ASC_DLLSPEC union RelationTermUnion *FreeStore_GetMem();
111 /**<
112 * This function returns a marked block to the caller. When not needed
113 * any more the user must use FreeMem(term).
114 * It is the users responsibility to remember
115 * which store that he/she got his block from. It is envisioned that multiple
116 * freestore could be used, such as a store for parse nodes that will last
117 * throughout the life of the code, and a store for relation terms that
118 * are of dynamic nature, such as in doing symbolic manipulations on a
119 * relation.
120 */
121
122 ASC_DLLSPEC int FreeStore_FreeMem(union RelationTermUnion *term);
123 /**<
124 * This function returns a block of memory that was obtained from a
125 * freestore. The appropriate store must be set a priori.
126 * Return 1 in case of invalid call.
127 */
128
129 extern union RelationTermUnion
130 *FreeStoreCheckMem(union RelationTermUnion *term);
131 /**<
132 * This will function will return a non NULL pointer if the memory
133 * associated with the term was allocated from the currently active
134 * freestore.
135 */
136
137 ASC_DLLSPEC void FreeStore_SetFreeStore(struct FreeStore *store);
138 /**< Set the current working freestore. */
139 ASC_DLLSPEC struct FreeStore *FreeStore_GetFreeStore(void);
140 /**< Retrieve the current working freestore. */
141
142 /* @} */
143
144 #endif /* ASC_FREESTORE_H */
145

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22