C:/Users/Dennis/src/lang/russell.orig/src/gc/interface.c

Go to the documentation of this file.
00001 #include "gc_private.h"
00002 #include <stddef.h>
00003 
00004 /* These are some additional routines to interface the collector to C     */
00005 /* This is a rather special purpose interface that tries to keep down the */
00006 /* number of collections in the presence of explicit deallocations.       */
00007 /* A call to this malloc effectively declares that the resulting object   */
00008 /* will be explicitly deallocated with very high probability.             */
00009 /* The reduced collection frequency may interfere with object             */
00010 /* coalescing.                                                            */
00011 /* If you just want to rename GC_malloc and friends, this is NOT          */
00012 /* the right way to do it.                                                */
00013 
00014 /* This contributed by David Chase (chase@eng.sun.com) a long time        */
00015 /* ago. Much of its original functionality has since been absorbed        */
00016 /* elsewhere.                                                             */
00017 /* They illustrates the use of GC_non_gc_bytes                            */
00018 /* Hacked by H. Boehm (11/16/89) to accomodate GC_realloc.                */
00019 /* Further updated (2/20/92) to reflect changes in interfaces and data    */
00020 /* structures.                                                            */
00021 /* Further updated (8/25/92) to correct previously introduced bugs and    */
00022 /* make it compile with semi-modern compilers.                            */
00023 /* Note that extern_ptr_t is either void * or char *, as appropriate.     */
00024 
00025 
00026 /* This free routine is merely advisory -- it reduces the estimate of
00027    storage that won't be reclaimed in the next collection, thus
00028    making it more likely that the collector will run next time more
00029    memory is needed. */
00030 
00031 void free(p)
00032 extern_ptr_t p;
00033 {
00034   size_t inc = GC_size(p);
00035   GC_non_gc_bytes -= inc;
00036 }
00037 
00038 /* This free routine adjusts the collector estimates of space in use,
00039    but also actually releases the memory for reuse.  It is thus "unsafe"
00040    if the programmer "frees" memory that is actually still in use.  */
00041 
00042 void unsafe_free(p)
00043 extern_ptr_t p;
00044 {
00045   size_t inc = GC_size(p);
00046   GC_non_gc_bytes -= inc;
00047   GC_free(p);
00048 }
00049 
00050 
00051 /* malloc and malloc_atomic are obvious substitutes for the C library
00052    malloc.  Note that the storage so allocated is regarded as not likely
00053    to be reclaimed by the collector (until explicitly freed), and thus
00054    its size is added to non_gc_bytes.
00055 */
00056 
00057 extern_ptr_t malloc(bytesize)
00058 size_t bytesize;
00059 {
00060   extern_ptr_t result;
00061   
00062   result = (extern_ptr_t) GC_malloc (bytesize);
00063   GC_non_gc_bytes += (bytesize + 3) & ~3;
00064   return result;
00065 }
00066 
00067 extern_ptr_t malloc_atomic(bytesize)
00068 size_t bytesize;
00069 {
00070   extern_ptr_t result;
00071   
00072   result = (extern_ptr_t) GC_malloc_atomic (bytesize);
00073   GC_non_gc_bytes += (bytesize + 3) & ~3;
00074   return result;
00075 }
00076 
00077 extern_ptr_t realloc(old,size)
00078 extern_ptr_t old;
00079 size_t size;
00080 {
00081   int inc = GC_size(old);
00082 
00083   GC_non_gc_bytes += ((size + 3) & ~3) - inc;
00084   return(GC_realloc(old, size));
00085 }
00086 

Generated on Fri Jan 25 10:39:45 2008 for russell by  doxygen 1.5.4