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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 98.1p1 release (March 2nd, 1998)
originally by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Life Time of Terms</TITLE>
<META NAME="description" CONTENT="Life Time of Terms">
<META NAME="keywords" CONTENT="tpman">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="tpman.css">
<LINK REL="next" HREF="node11.html">
<LINK REL="previous" HREF="node9.html">
<LINK REL="up" HREF="node6.html">
<LINK REL="next" HREF="node11.html">
</HEAD>
<BODY >
<!--Navigation Panel-->
<A NAME="tex2html247"
HREF="node11.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="/usr/share/latex2html/icons/next.png"></A>
<A NAME="tex2html243"
HREF="node6.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="/usr/share/latex2html/icons/up.png"></A>
<A NAME="tex2html237"
HREF="node9.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="/usr/share/latex2html/icons/prev.png"></A>
<A NAME="tex2html245"
HREF="node4.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
SRC="/usr/share/latex2html/icons/contents.png"></A>
<A NAME="tex2html246"
HREF="node58.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
SRC="/usr/share/latex2html/icons/index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html248"
HREF="node11.html">Function Definitions</A>
<B> Up:</B> <A NAME="tex2html244"
HREF="node6.html">Input</A>
<B> Previous:</B> <A NAME="tex2html238"
HREF="node9.html">Storage Options</A>
<BR>
<BR>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION00064000000000000000">
Life Time of Terms</A>
</H2>
Terms maintained under non-unique storage can be freed using a <I>free_</I><EM>phylum</EM> call.
Terms maintained under unique storage cannot be freed individually.
They are stored via hashtables, and their lifetime can only be controlled by
manipulation of their hashtables.
By default, Kimwitu stores all unique terms in the same hashtable.
The following manipulations on hashtables are defined: creation, assignment,
deletion and reuse.
New, initially empty, hashtables of arbitrary size can be created and used instead of the default hashtable.
A newly created hashtable is not used directly after creation, but only after it has been `assigned' -
from that moment on it will be used instead of the previously assigned hashtable, until another hashtable gets assigned.
A `de-assigned' hashtable is not freed; all its memory cells remain alive, so pointers to those cells remain valid.
However, they are invisible to the create routines, and thus the unique storage guarantee no longer holds in the
following sequence of events:
an (uniquely maintained) operator is created with a certain set of arguments, and a memory cell for it is created in the hashtable, and the initialization code for its phylum is executed;
a new hashtable is created and assigned;
the same operator is called with the same set of arguments, a new memory cell for it is created in the new hashtable, and the initialization code for its phylum is executed again.
A `de-assigned' hashtable can be freed when its memory cells are no longer needed.
<P>
This can be used to control the lifetime of unique terms quite effectively, eg. to free intermediate results of a computation,
as follows.
First, a `temporary' hashtable is created to hold the intermediate results.
Then, just before the computation is started, replace the default hashtable with the temporary one.
When the computation is finished, the intermediate results and the final result are in the `temporary' hashtable.
Re-assign the `old' hashtable, and copy the final result<A NAME="tex2html2"
HREF="footnode.html#foot1344"><SUP>2</SUP></A>,
to re-create the memory cells belonging to the final result in the `old' hashtable.
Finally, free the `temporary' hashtable.
<P>
Often only a limited number of phyla appears in the intermediate results.
To allow more precise control, the phyla maintained under unique storage can be partitioned over multiple <EM>storage-classes</EM>,
that each can have its own hashtable assigned.
The memory cells created for a phylum are created in the hashtable assigned to the phylum's storage-class.
Usually, phyla with a different `lifetime' will be in different storage classes.
There is one predefined storage-class: <EM>uniq</EM>.
Other storage-classes can be defined and used as follows:<A NAME="174"> </A>
<PRE><HR><!--lgrindfile: storage_classes_example.k 12:21 Oct 26 1992-->
%storageclass intermediate wholeprogram; <I>/* the `%' is part of the keyword */</I>
<BR>
ID2 { intermediate }: Operator1( ... ) | Operator2( ... ) | ... ;
ID3 { wholeprogram }: Operator3( ... );
<HR></PRE>
Here <I>ID2</I> and <I>ID3</I> belong to different storage-classes;
if different hashtables are assigned to <I>intermediate</I> and <I>wholeprogram</I>, then
the memory cells for <I>Operator1</I> and <I>Operator2</I> will be in another hashtable than
those for <I>Operator3</I>.
<P>
A phylum can be in only <EM>one</EM> storage class.
The term processor reports an error if this condition is violated.
The <I>%storageclass</I> declaration is optional;
if <EM>Kimwitu</EM> input does contain a storage class declaration,
errors will be reported for all storage classes that were not explicitly
declared.
<P>
For each storage class, Kimwitu creates statically (at compile time) a hashtable.
Dynamically, hashtables can be created, (re)assigned to one or more storage
classes, cleared and freed.
The hashtable functions are listed in Section <A HREF="node17.html#gen-func">2.2</A>.
<P>
If the default (statically allocated) hashtable is not used, ie. if
all storage classes are reassigned to dynamically created hashtables
<EM>before they are used</EM>, it is useful to redefine <I>LARGEPRIME</I><A NAME="1345"> </A> :
<PRE><HR><!--lgrindfile: redefine_LARGEPRIME_example.k 15:00 Sep 28 1992-->
%{ KC_TYPES_HEADER
<B>#define</B> LARGEPRIME 0
%}
<HR></PRE>
or use the <I>-DLARGEPRIME=0</I> flag with <I>cc</I> during compilation of file <I>k.c</I> (see Section <A HREF="node20.html#overviewGeneratedNames">2.5</A>),
to avoid the creation of the statically allocated hashtable.
<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html247"
HREF="node11.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="/usr/share/latex2html/icons/next.png"></A>
<A NAME="tex2html243"
HREF="node6.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="/usr/share/latex2html/icons/up.png"></A>
<A NAME="tex2html237"
HREF="node9.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="/usr/share/latex2html/icons/prev.png"></A>
<A NAME="tex2html245"
HREF="node4.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
SRC="/usr/share/latex2html/icons/contents.png"></A>
<A NAME="tex2html246"
HREF="node58.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
SRC="/usr/share/latex2html/icons/index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html248"
HREF="node11.html">Function Definitions</A>
<B> Up:</B> <A NAME="tex2html244"
HREF="node6.html">Input</A>
<B> Previous:</B> <A NAME="tex2html238"
HREF="node9.html">Storage Options</A>
<!--End of Navigation Panel-->
<ADDRESS>
<I></I>
<BR><I>2000-04-17</I>
</ADDRESS>
</BODY>
</HTML>
|