1 /* gc.c -- Functions to remember and garbage collect unused node contents.
2 $Id: gc.c,v 1.7 2008/06/11 09:55:42 gray Exp $
4 Copyright (C) 1993, 2004, 2007, 2008 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or (at
9 your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Written by Brian Fox (bfox@ai.mit.edu). */
23 /* Array of pointers to the contents of gc-able nodes. A pointer on this
24 list can be garbage collected when no info window contains a node whose
25 contents member match the pointer. */
26 static char **gcable_pointers = NULL;
27 static int gcable_pointers_index = 0;
28 static int gcable_pointers_slots = 0;
30 /* Add POINTER to the list of garbage collectible pointers. A pointer
31 is not actually garbage collected until no info window contains a node
32 whose contents member is equal to the pointer. */
34 add_gcable_pointer (char *pointer)
37 add_pointer_to_array (pointer, gcable_pointers_index, gcable_pointers,
38 gcable_pointers_slots, 10, char *);
41 /* Grovel the list of info windows and gc-able pointers finding those
42 node->contents which are collectible, and free them. */
52 if (!info_windows || !gcable_pointers_index)
55 for (i = 0; (iw = info_windows[i]); i++)
57 for (j = 0; j < iw->nodes_index; j++)
59 NODE *node = iw->nodes[j];
61 /* If this node->contents appears in our list of gcable_pointers,
62 it is not gc-able, so save it. */
63 for (k = 0; k < gcable_pointers_index; k++)
64 if (gcable_pointers[k] == node->contents)
67 (node->contents, new_index, new, new_slots, 10, char *);
73 /* We have gathered all of the pointers which need to be saved. Free any
74 of the original pointers which do not appear in the new list. */
75 for (i = 0; i < gcable_pointers_index; i++)
77 for (j = 0; j < new_index; j++)
78 if (gcable_pointers[i] == new[j])
81 /* If we got all the way through the new list, then the old pointer
82 can be garbage collected. */
84 free (gcable_pointers[i]);
87 free (gcable_pointers);
88 gcable_pointers = new;
89 gcable_pointers_slots = new_slots;
90 gcable_pointers_index = new_index;