source: trunk/gcc/boehm-gc/doc/gc.man@ 3003

Last change on this file since 3003 was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.5 KB
Line 
1.TH GC_MALLOC 1L "12 February 1996"
2.SH NAME
3GC_malloc, GC_malloc_atomic, GC_free, GC_realloc, GC_enable_incremental, GC_register_finalizer, GC_malloc_ignore_off_page, GC_malloc_atomic_ignore_off_page, GC_set_warn_proc \- Garbage collecting malloc replacement
4.SH SYNOPSIS
5#include "gc.h"
6.br
7# define malloc(n) GC_malloc(n)
8.br
9... malloc(...) ...
10.br
11.sp
12cc ... gc.a
13.LP
14.SH DESCRIPTION
15.I GC_malloc
16and
17.I GC_free
18are plug-in replacements for standard malloc and free. However,
19.I
20GC_malloc
21will attempt to reclaim inaccessible space automatically by invoking a conservative garbage collector at appropriate points. The collector traverses all data structures accessible by following pointers from the machines registers, stack(s), data, and bss segments. Inaccessible structures will be reclaimed. A machine word is considered to be a valid pointer if it is an address inside an object allocated by
22.I
23GC_malloc
24or friends.
25.LP
26See the documentation in the include file gc_cpp.h for an alternate, C++ specific interface to the garbage collector.
27.LP
28Unlike the standard implementations of malloc,
29.I
30GC_malloc
31clears the newly allocated storage.
32.I
33GC_malloc_atomic
34does not. Furthermore, it informs the collector that the resulting object will never contain any pointers, and should therefore not be scanned by the collector.
35.LP
36.I
37GC_free
38can be used to deallocate objects, but its use is optional, and generally discouraged.
39.I
40GC_realloc
41has the standard realloc semantics. It preserves pointer-free-ness.
42.I
43GC_register_finalizer
44allows for registration of functions that are invoked when an object becomes inaccessible.
45.LP
46The garbage collector tries to avoid allocating memory at locations that already appear to be referenced before allocation. (Such apparent ``pointers'' are usually large integers and the like that just happen to look like an address.) This may make it hard to allocate very large objects. An attempt to do so may generate a warning.
47.LP
48.I
49GC_malloc_ignore_off_page
50and
51.I
52GC_malloc_atomic_ignore_off_page
53inform the collector that the client code will always maintain a pointer to near the beginning of the object (within the first 512 bytes), and that pointers beyond that can be ignored by the collector. This makes it much easier for the collector to place large objects. These are recommended for large object allocation. (Objects expected to be larger than about 100KBytes should be allocated this way.)
54.LP
55It is also possible to use the collector to find storage leaks in programs destined to be run with standard malloc/free. The collector can be compiled for thread-safe operation. Unlike standard malloc, it is safe to call malloc after a previous malloc call was interrupted by a signal, provided the original malloc call is not resumed.
56.LP
57The collector may, on rare occasion produce warning messages. On UNIX machines these appear on stderr. Warning messages can be filtered, redirected, or ignored with
58.I
59GC_set_warn_proc.
60This is recommended for production code. See gc.h for details.
61.LP
62Debugging versions of many of the above routines are provided as macros. Their names are identical to the above, but consist of all capital letters. If GC_DEBUG is defined before gc.h is included, these routines do additional checking, and allow the leak detecting version of the collector to produce slightly more useful output. Without GC_DEBUG defined, they behave exactly like the lower-case versions.
63.LP
64On some machines, collection will be performed incrementally after a call to
65.I
66GC_enable_incremental.
67This may temporarily write protect pages in the heap. See the README file for more information on how this interacts with system calls that write to the heap.
68.LP
69Other facilities not discussed here include limited facilities to support incremental collection on machines without appropriate VM support, provisions for providing more explicit object layout information to the garbage collector, more direct support for ``weak'' pointers, support for ``abortable'' garbage collections during idle time, etc.
70.LP
71.SH "SEE ALSO"
72The README and gc.h files in the distribution. More detailed definitions of the functions exported by the collector are given there. (The above list is not complete.)
73.LP
74Boehm, H., and M. Weiser, "Garbage Collection in an Uncooperative Environment",
75\fISoftware Practice & Experience\fP, September 1988, pp. 807-820.
76.LP
77The malloc(3) man page.
78.LP
79.SH AUTHOR
80Hans-J. Boehm (boehm@parc.xerox.com). Some of the code was written by others, most notably Alan Demers.
Note: See TracBrowser for help on using the repository browser.