8 * @file Memory management routines
12 static void compandtake(word, word *, word *, word *, bool);
13 static void sinsert(word);
15 static void compandtake();
16 static void sinsert();
20 int compactify_allowed=1;
21 #define space 400 /* words */
24 void request(word app, word *ah, word *am)
27 bool wascompactified, found;
31 wascompactified = FALSE;
33 if (compactify_allowed && thisp->force_compactification) {
35 thisp->force_compactification = FALSE;
36 wascompactified = TRUE;
39 /* reserve dictionary item */
40 if (thisp->freeitem != 0) {
41 *ah = thisp->freeitem;
42 thisp->freeitem = M[*ah];
45 *ah = thisp->lastitem - 2;
46 /* cannot take free item */
47 if (*ah <= thisp->lastused + space) {
48 if (compactify_allowed) {
49 if(!wascompactified) {
51 wascompactified = TRUE;
54 thisp->force_compactification = TRUE;
56 *ah = thisp->lastitem - 2;
57 if (*ah <= thisp->lastused)
61 thisp->lastitem = *ah;
65 /* now we have a free dict. item */
67 /* special case app=2 */
68 if (app == 2 && thisp->headk2 != 0) {
70 thisp->headk2 = M[*am + SHORTLINK];
72 word t1 = thisp->headk;
75 while (t1 != thisp->lower && !found) {
79 else if (t2 - app >= 2)
83 t1 = M[t1 + LONGLINK];
87 t5 = M[t1 + SHORTLINK];
89 M[t5 + LONGLINK] = M[t1 + LONGLINK];
91 t5 = M[t1 + LONGLINK];
95 M[t4 + LONGLINK] = t5;
98 /* at least two extra words */
104 } else if (thisp->lastitem - thisp->lastused > app + space) {
105 *am = thisp->lastused+1;
106 thisp->lastused += app;
108 /* return dictionary item */
109 M[*ah] = thisp->freeitem;
110 thisp->freeitem = *ah;
111 if(compactify_allowed) {
112 if( !wascompactified )
115 thisp->force_compactification = TRUE;
117 /* reserve dictionary item */
118 *ah = thisp->lastitem-2;
119 thisp->lastitem = *ah;
122 if (thisp->lastitem - thisp->lastused > app) {
123 *am = thisp->lastused + 1;
124 thisp->lastused += app;
131 for (t2 = *am+1; t2 < *am + app; t2++)
137 /* Dispose of a memory item. */
138 static void sinsert(word am)
143 /* a special list should be used */
145 M[am + SHORTLINK] = thisp->headk2;
151 /* look for a proper place */
155 /* an entry with matching appetite */
157 M[am + SHORTLINK] = M[t2 + SHORTLINK];
158 M[t2 + SHORTLINK] = am;
162 M[am + LONGLINK] = t2;
163 M[am + SHORTLINK] = 0;
167 M[t4 + LONGLINK] = am;
172 t2 = M[t2 + LONGLINK];
181 void disp(virtaddr *virt)
185 t1 = M[virt->addr + 1];
187 if (t1 == virt->mark) {
192 M[virt->addr + 1] = t1;
193 /* mark still usable */
194 if (t1 != MAXMARKER) {
195 M[virt->addr] = thisp->freeitem;
196 thisp->freeitem = virt->addr;
199 /* now dictionary item is released */
201 /* on the boundary */
202 if (t2 + M[t2] - 1 == thisp->lastused)
203 thisp->lastused = t2 - 1;
210 * Compute available memory size
216 /* contiguos memory */
217 avail = thisp->lastitem-thisp->lastused - 1;
218 /* go through killed 2 list */
222 t1 = M[t1 + SHORTLINK];
225 /* go through killed object list */
226 while (t1 != thisp->lower) {
230 t2 = M[t2 + SHORTLINK];
232 t1 = M[t1 + LONGLINK];
234 /* go through free item list */
235 t1 = thisp->freeitem;