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 the program; if not, write to the Free Software |
27 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check |
28 |
* the file named COPYING. |
29 |
*/ |
30 |
|
31 |
/** @file |
32 |
* Implementation of Free Store Module. |
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 |
* <pre> |
39 |
* When #including freestore.h, make sure these files are #included first: |
40 |
* #include "utilities/ascConfig.h" |
41 |
* #include "compiler.h" |
42 |
* #include "stack.h" |
43 |
* #include "exprsym.h" |
44 |
* </pre> |
45 |
*/ |
46 |
|
47 |
#ifndef ASC_FREESTORE_H |
48 |
#define ASC_FREESTORE_H |
49 |
|
50 |
/** addtogroup compiler Compiler |
51 |
@{ |
52 |
*/ |
53 |
|
54 |
/** Free store data structure. */ |
55 |
struct FreeStore { |
56 |
union RelationTermUnion **root; /**< ptr to it all */ |
57 |
union RelationTermUnion *next_free; /**< ptr to next_clean slot */ |
58 |
struct gs_stack_t *returned; /**< stack of returned blocks */ |
59 |
int n_buffers; /**< # of big chunks */ |
60 |
int buffer_length; /**< size of chunks */ |
61 |
int row; /**< index of the next free location's row */ |
62 |
int col; /**< index of the next free locations's col */ |
63 |
}; |
64 |
|
65 |
extern long FreeStore_UnitsAllocated(); |
66 |
/**< Retrieve the number of free store units allocated. */ |
67 |
extern void FreeStore__Statistics(FILE *fp, struct FreeStore *store); |
68 |
/**< Print stats about the free store to fp. */ |
69 |
|
70 |
extern void FreeStore__BlastMem(struct FreeStore *store); |
71 |
/**< |
72 |
* This function deallocates *all* the memory associated with a free |
73 |
* store. The free store should not be referenced after this call. |
74 |
*/ |
75 |
|
76 |
/* |
77 |
* These are the normal user level routines. |
78 |
* |
79 |
* Known Bugs: |
80 |
* The blocks returned the user are never anything but the size of |
81 |
* a relation token. This is not highly reuseable. |
82 |
* |
83 |
* Features?: |
84 |
* This module runs a stack of free_stores, which is sometimes |
85 |
* handy, to avoid passing around a free_store pointer. Note, |
86 |
* however, that it costs just as much to dereference the global |
87 |
* variables as it does to pass the store pointer. |
88 |
*/ |
89 |
|
90 |
extern struct FreeStore *FreeStore_Create(int n_buffers, int buffer_length); |
91 |
/**< |
92 |
* Create a new free store with 1 buffer of size buffer length. |
93 |
* The information within the buffer is *not* initialized in any way. |
94 |
*/ |
95 |
|
96 |
extern void FreeStore_ReInit(struct FreeStore *store); |
97 |
/**< |
98 |
* Reinitializes the free store. This simply tells the free store to |
99 |
* *forget* about anything that may have be allotted to a user. In other |
100 |
* words, after this call the freestore will behave as if it was just |
101 |
* created. Any information that a user wants, had better be copied before |
102 |
* this call, as it is now a candidate to be allotted to someone else. |
103 |
*/ |
104 |
|
105 |
extern union RelationTermUnion *GetMem(); |
106 |
/**< |
107 |
* This function returns a marked block to the caller. When not needed |
108 |
* any more the user must use FreeMem(term). |
109 |
* It is the users responsibility to remember |
110 |
* which store that he/she got his block from. It is envisioned that multiple |
111 |
* freestore could be used, such as a store for parse nodes that will last |
112 |
* throughout the life of the code, and a store for relation terms that |
113 |
* are of dynamic nature, such as in doing symbolic manipulations on a |
114 |
* relation. |
115 |
*/ |
116 |
|
117 |
extern void FreeMem(union RelationTermUnion *term); |
118 |
/**< |
119 |
* This function returns a block of memory that was obtained from a |
120 |
* freestore. The appropriate store must be set a priori. |
121 |
*/ |
122 |
|
123 |
extern union RelationTermUnion |
124 |
*FreeStoreCheckMem(union RelationTermUnion *term); |
125 |
/**< |
126 |
* This will function will return a non NULL pointer if the memory |
127 |
* associated with the term was allocated from the currently active |
128 |
* freestore. |
129 |
*/ |
130 |
|
131 |
extern void FreeStore_SetFreeStore(struct FreeStore *store); |
132 |
/**< Set the current working freestore. */ |
133 |
extern struct FreeStore *FreeStore_GetFreeStore(void); |
134 |
/**< Retrieve the current working freestore. */ |
135 |
|
136 |
/* @} */ |
137 |
|
138 |
#endif /* ASC_FREESTORE_H */ |
139 |
|