4 * Control of memory allocation
6 * © 1994-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Glass.
13 * Glass is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Glass is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with Glass. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /*----- Header files ------------------------------------------------------*/
31 * ANSI standard headers
41 #include "steel/Steel.h"
43 #include "steel/buttons.h"
44 #include "steel/bbc.h"
47 extern void flex_dump(const char *p);
59 /*----- Static variables --------------------------------------------------*/
61 static heap_infostr indir__info;
62 static BOOL indir__outOfDate;
63 static dbox indir__dbox;
65 /*----- Support routines --------------------------------------------------*/
68 * void indir__update(void *handle)
71 * Updates the heap info window if necessary
74 static void indir__update(void *handle)
79 indir__info=heap_info();
80 dbox_setfield(indir__dbox,
83 utils_cvtSize(indir__info.size));
84 dbox_setfield(indir__dbox,
87 utils_cvtSize(indir__info.free));
88 dbox_setfield(indir__dbox,
91 utils_cvtSize(indir__info.largest));
92 buttons_updateSlider(indir__dbox,
95 indir__info.size-indir__info.free,
101 win_removeIdleClaimer(indir__update,0);
102 indir__outOfDate=FALSE;
106 /*----- Event handlers ----------------------------------------------------*/
109 * void indir__dboxRedraw(wimp_redrawstr *r,void *handle)
112 * Redraws the dbox used to show heap information
115 * wimp_redrawstr *r == information about the redraw
116 * void *handle == a pointer (ignored)
119 static void indir__dboxRedraw(wimp_redrawstr *r,void *handle)
123 buttons_redrawSlider(indir__dbox,glass_HEAPSLIDE,indir__info.size,
124 indir__info.size-indir__info.free,11,FALSE);
128 * BOOL indir__dboxRaw(dbox d,wimp_eventstr *e,void *handle)
131 * Handles raw events (just redraw requests for the moment) for the heap
135 * dbox d == the dbox handle
136 * wimp_eventstr *e == the event that occurred
137 * void *handle == a pointer (ignored)
140 * TRUE if the event has been dealt with
143 static BOOL indir__dboxRaw(dbox d,wimp_eventstr *e,void *handle)
151 wimpt_redraw(indir__dboxRedraw,0);
159 * void indir__dboxHandler(dbox d,dbox_field f,void *handle)
162 * Handles events for the heap info dialogue box.
165 * dbox d == the dbox handle
166 * dbox_field f == the event that occurred
167 * void *handle == a pointer (ignored)
170 static void indir__dboxHandler(dbox d,dbox_field f,void *handle)
177 win_remove_idle_claimer(indir__update,0);
188 flex_dump("Glass flex dump");
197 help_addLine(msgs_lookup("idhHPINF"));
203 /*----- External routines -------------------------------------------------*/
206 * void indir_init(void)
209 * Jumps in to ensure that indir gets the first flex block, so it doesn't
213 void indir_init(void)
219 * void *indir_alloc(int size)
222 * Allocate memory from heap.
225 * int size == the number of bytes the caller wants
228 void *indir_alloc(size_t size)
230 if (!indir__outOfDate)
232 indir__outOfDate=TRUE;
233 win_addIdleClaimer(indir__update,win_DONTCARE,0);
235 return (heap_alloc(size));
239 * void indir_free(void *p)
242 * Reclaims the memory from the block pointed to by p. Some simple checks
243 * are used to ensure that p is valid.
246 * void *p == pointer to a block to free.
249 void indir_free(void *p)
251 if (!indir__outOfDate)
253 indir__outOfDate=TRUE;
254 win_addIdleClaimer(indir__update,win_DONTCARE,0);
260 * void *indir_realloc(void *p,int newsize)
263 * Resizes a heap block.
266 * void *p == pointer to block to resize
267 * int newsize == the new size to make it
270 * Pointer to the block (may have moved) or 0 (failure, block didn't move)
273 void *indir_realloc(void *p,int newsize)
275 if (!indir__outOfDate)
277 indir__outOfDate=TRUE;
278 win_addIdleClaimer(indir__update,win_DONTCARE,0);
280 return (heap_realloc(p,newsize));
284 * void indir_heapInfo(void)
287 * Displays a dialogue box showing current heap stats
290 void indir_heapInfo(void)
294 indir__dbox=dbox_create("heapInfo");
295 indir__outOfDate=FALSE;
298 dbox_shadeicon(indir__dbox,9,TRUE);
300 dbox_eventHandler(indir__dbox,indir__dboxHandler,0);
301 dbox_rawEventHandler(indir__dbox,indir__dboxRaw,0);
303 dbox_display(indir__dbox,dbox_STATIC_LASTPOS);