comparison src/alloc.c @ 3305:1043bbfa24cf

[xemacs-hg @ 2006-03-26 15:24:25 by crestani] 2006-03-26 Marcus Crestani <crestani@xemacs.org> * alloc.c (malloc_warning): Move function into scope of MALLOC_END, add MALLOC_END. * alloc.c (memory_full): Add memory shortage indication, adjust error messages. * mc-alloc.c: Add memory_shortage. * mc-alloc.c (expand_heap): If memory is short, allocate only the needed pages, not more. * mc-alloc.h: Add memory_shortage.
author crestani
date Sun, 26 Mar 2006 15:24:27 +0000
parents 73051095a712
children 721daee0fcd8
comparison
equal deleted inserted replaced
3304:73051095a712 3305:1043bbfa24cf
228 breathing_space = 0; 228 breathing_space = 0;
229 xfree (tmp, void *); 229 xfree (tmp, void *);
230 } 230 }
231 } 231 }
232 #endif /* not NEW_GC */ 232 #endif /* not NEW_GC */
233
234 /* malloc calls this if it finds we are near exhausting storage */
235 void
236 malloc_warning (const char *str)
237 {
238 if (ignore_malloc_warnings)
239 return;
240
241 warn_when_safe
242 (Qmemory, Qemergency,
243 "%s\n"
244 "Killing some buffers may delay running out of memory.\n"
245 "However, certainly by the time you receive the 95%% warning,\n"
246 "you should clean up, kill this Emacs, and start a new one.",
247 str);
248 }
249
250 /* Called if malloc returns zero */
251 DOESNT_RETURN
252 memory_full (void)
253 {
254 fprintf (stderr, "##### M E M O R Y F U L L #####\n");
255 /* Force a GC next time eval is called.
256 It's better to loop garbage-collecting (we might reclaim enough
257 to win) than to loop beeping and barfing "Memory exhausted"
258 */
259 consing_since_gc = gc_cons_threshold + 1;
260 recompute_need_to_garbage_collect ();
261 #ifndef NEW_GC
262 release_breathing_space ();
263 #endif /* not NEW_GC */
264
265 /* Flush some histories which might conceivably contain garbalogical
266 inhibitors. */
267 if (!NILP (Fboundp (Qvalues)))
268 Fset (Qvalues, Qnil);
269 Vcommand_history = Qnil;
270
271 out_of_memory ("Memory exhausted", Qunbound);
272 }
273 233
274 static void 234 static void
275 set_alloc_mins_and_maxes (void *val, Bytecount size) 235 set_alloc_mins_and_maxes (void *val, Bytecount size)
276 { 236 {
277 if (!val) 237 if (!val)
350 malloc_after (void *val, Bytecount size) 310 malloc_after (void *val, Bytecount size)
351 { 311 {
352 if (!val && size != 0) 312 if (!val && size != 0)
353 memory_full (); 313 memory_full ();
354 set_alloc_mins_and_maxes (val, size); 314 set_alloc_mins_and_maxes (val, size);
315 }
316
317 /* malloc calls this if it finds we are near exhausting storage */
318 void
319 malloc_warning (const char *str)
320 {
321 if (ignore_malloc_warnings)
322 return;
323
324 /* Remove the malloc lock here, because warn_when_safe may allocate
325 again. It is safe to remove the malloc lock here, because malloc
326 is already finished (malloc_warning is called via
327 after_morecore_hook -> check_memory_limits -> save_warn_fun ->
328 malloc_warning). */
329 MALLOC_END ();
330
331 warn_when_safe
332 (Qmemory, Qemergency,
333 "%s\n"
334 "Killing some buffers may delay running out of memory.\n"
335 "However, certainly by the time you receive the 95%% warning,\n"
336 "you should clean up, kill this Emacs, and start a new one.",
337 str);
338 }
339
340 /* Called if malloc returns zero */
341 DOESNT_RETURN
342 memory_full (void)
343 {
344 /* Force a GC next time eval is called.
345 It's better to loop garbage-collecting (we might reclaim enough
346 to win) than to loop beeping and barfing "Memory exhausted"
347 */
348 consing_since_gc = gc_cons_threshold + 1;
349 recompute_need_to_garbage_collect ();
350 #ifdef NEW_GC
351 /* Put mc-alloc into memory shortage mode. This may keep XEmacs
352 alive until the garbage collector can free enough memory to get
353 us out of the memory exhaustion. If already in memory shortage
354 mode, we are in a loop and hopelessly lost. */
355 if (memory_shortage)
356 {
357 fprintf (stderr, "Memory full, cannot recover.\n");
358 ABORT ();
359 }
360 fprintf (stderr,
361 "Memory full, try to recover.\n"
362 "You should clean up, kill this Emacs, and start a new one.\n");
363 memory_shortage++;
364 #else /* not NEW_GC */
365 release_breathing_space ();
366 #endif /* not NEW_GC */
367
368 /* Flush some histories which might conceivably contain garbalogical
369 inhibitors. */
370 if (!NILP (Fboundp (Qvalues)))
371 Fset (Qvalues, Qnil);
372 Vcommand_history = Qnil;
373
374 out_of_memory ("Memory exhausted", Qunbound);
355 } 375 }
356 376
357 /* like malloc, calloc, realloc, free but: 377 /* like malloc, calloc, realloc, free but:
358 378
359 -- check for no memory left 379 -- check for no memory left