⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻
📖 第 1 页 / 共 2 页
字号:
collector doesn't already understand them.)  On some machines, it maybe desirable to set GC_stacktop to a good approximation of the stack base. (This enhances code portability on HP PA machines, since there is nogood way for the collector to compute this value.)  Client code may include"gc.h", which defines all of the following, plus many others.1)  GC_malloc(nbytes)    - allocate an object of size nbytes.  Unlike malloc, the object is      cleared before being returned to the user.  Gc_malloc will      invoke the garbage collector when it determines this to be appropriate.      GC_malloc may return 0 if it is unable to acquire sufficient      space from the operating system.  This is the most probable      consequence of running out of space.  Other possible consequences      are that a function call will fail due to lack of stack space,      or that the collector will fail in other ways because it cannot      maintain its internal data structures, or that a crucial system      process will fail and take down the machine.  Most of these      possibilities are independent of the malloc implementation.2)  GC_malloc_atomic(nbytes)    - allocate an object of size nbytes that is guaranteed not to contain any      pointers.  The returned object is not guaranteed to be cleared.      (Can always be replaced by GC_malloc, but results in faster collection      times.  The collector will probably run faster if large character      arrays, etc. are allocated with GC_malloc_atomic than if they are      statically allocated.)3)  GC_realloc(object, new_size)    - change the size of object to be new_size.  Returns a pointer to the      new object, which may, or may not, be the same as the pointer to      the old object.  The new object is taken to be atomic iff the old one      was.  If the new object is composite and larger than the original object,      then the newly added bytes are cleared (we hope).  This is very likely      to allocate a new object, unless MERGE_SIZES is defined in gc_priv.h.      Even then, it is likely to recycle the old object only if the object      is grown in small additive increments (which, we claim, is generally bad      coding practice.)4)  GC_free(object)    - explicitly deallocate an object returned by GC_malloc or      GC_malloc_atomic.  Not necessary, but can be used to minimize      collections if performance is critical.  Probably a performance      loss for very small objects (<= 8 bytes).5)  GC_expand_hp(bytes)    - Explicitly increase the heap size.  (This is normally done automatically      if a garbage collection failed to GC_reclaim enough memory.  Explicit      calls to GC_expand_hp may prevent unnecessarily frequent collections at      program startup.)6)  GC_malloc_ignore_off_page(bytes)	- identical to GC_malloc, but the client promises to keep a pointer to	  the somewhere within the first 256 bytes of the object while it is	  live.  (This pointer should nortmally be declared volatile to prevent	  interference from compiler optimizations.)  This is the recommended	  way to allocate anything that is likely to be larger than 100Kbytes	  or so.  (GC_malloc may result in failure to reclaim such objects.)7)  GC_set_warn_proc(proc)	- Can be used to redirect warnings from the collector.  Such warnings	  should be rare, and should not be ignored during code development.      8) GC_enable_incremental()    - Enables generational and incremental collection.  Useful for large      heaps on machines that provide access to page dirty information.      Some dirty bit implementations may interfere with debugging      (by catching address faults) and place restrictions on heap arguments      to system calls (since write faults inside a system call may not be      handled well).9) Several routines to allow for registration of finalization code.   User supplied finalization code may be invoked when an object becomes   unreachable.  To call (*f)(obj, x) when obj becomes inaccessible, use	GC_register_finalizer(obj, f, x, 0, 0);   For more sophisticated uses, and for finalization ordering issues,   see gc.h.  The global variable GC_free_space_divisor may be adjusted up from itsdefault value of 4 to use less space and more collection time, or down forthe opposite effect.  Setting it to 1 or 0 will effectively disable collectionsand cause all allocations to simply grow the heap.  The variable GC_non_gc_bytes, which is normally 0, may be changed to reflectthe amount of memory allocated by the above routines that should not beconsidered as a candidate for collection.  Careless use may, of course, resultin excessive memory consumption.  Some additional tuning is possible through the parameters definednear the top of gc_priv.h.    If only GC_malloc is intended to be used, it might be appropriate to define:#define malloc(n) GC_malloc(n)#define calloc(m,n) GC_malloc((m)*(n))  For small pieces of VERY allocation intensive code, gc_inl.hincludes some allocation macros that may be used in place of GC_mallocand friends.  All externally visible names in the garbage collector start with "GC_".To avoid name conflicts, client code should avoid this prefix, except whenaccessing garbage collector routines or variables.  There are provisions for allocation with explicit type information.This is rarely necessary.  Details can be found in gc_typed.h.THE C++ INTERFACE TO THE ALLOCATOR:  The Ellis-Hull C++ interface to the collector is included inthe collector distribution.  If you intend to use this, type"make c++" after the initial build of the collector is complete.See gc_cpp.h for the definition of the interface.  This interfacetries to approximate the Ellis-Detlefs C++ garbage collectionproposal without compiler changes.  Very often it will also be necessary to use gc_allocator.h and theallocator declared there to construct STL data structures.  Otherwisesubobjects of STL data structures wil be allcoated using a systemallocator, and objects they refer to may be prematurely collected.USE AS LEAK DETECTOR:  The collector may be used to track down leaks in C programs that areintended to run with malloc/free (e.g. code with extreme real-time orportability constraints).  To do so define FIND_LEAK in MakefileThis will cause the collector to invoke the report_leakroutine defined near the top of reclaim.c whenever an inaccessibleobject is found that has not been explicitly freed.  Such objects willalso be automatically reclaimed.  If all objects are allocated with GC_DEBUG_MALLOC (see next section), thenthe default version of report_leak will report at least the source file andline number at which the leaked object was allocated.  This may sometimes besufficient.  (On a few machines, it will also report a cryptic stack trace.If this is not symbolic, it can somethimes be called into a sympolic stacktrace by invoking program "foo" with "callprocs foo".  Callprocs is a shortshell script that invokes adb to expand program counter values to symbolicaddresses.  It was largely supplied by Scott Schwartz.)  Note that the debugging facilities described in the next section cansometimes be slightly LESS effective in leak finding mode, since inleak finding mode, GC_debug_free actually results in reuse of the object.(Otherwise the object is simply marked invalid.)  Also note that the testprogram is not designed to run meaningfully in FIND_LEAK mode.Use "make gc.a" to build the collector.DEBUGGING FACILITIES:  The routines GC_debug_malloc, GC_debug_malloc_atomic, GC_debug_realloc,and GC_debug_free provide an alternate interface to the collector, whichprovides some help with memory overwrite errors, and the like.Objects allocated in this way are annotated with additionalinformation.  Some of this information is checked during garbagecollections, and detected inconsistencies are reported to stderr.  Simple cases of writing past the end of an allocated object shouldbe caught if the object is explicitly deallocated, or if thecollector is invoked while the object is live.  The first deallocationof an object will clear the debugging info associated with anobject, so accidentally repeated calls to GC_debug_free will report thedeallocation of an object without debugging information.  Out ofmemory errors will be reported to stderr, in addition to returningNIL.  GC_debug_malloc checking  during garbage collection is enabledwith the first call to GC_debug_malloc.  This will result in someslowdown during collections.  If frequent heap checks are desired,this can be achieved by explicitly invoking GC_gcollect, e.g. fromthe debugger.  GC_debug_malloc allocated objects should not be passed to GC_reallocor GC_free, and conversely.  It is however acceptable to allocate onlysome objects with GC_debug_malloc, and to use GC_malloc for other objects,provided the two pools are kept distinct.  In this case, there is a verylow probablility that GC_malloc allocated objects may be misidentified ashaving been overwritten.  This should happen with probability at mostone in 2**32.  This probability is zero if GC_debug_malloc is never called.  GC_debug_malloc, GC_malloc_atomic, and GC_debug_realloc take twoadditional trailing arguments, a string and an integer.  These are notinterpreted by the allocator.  They are stored in the object (the string isnot copied).  If an error involving the object is detected, they are printed.  The macros GC_MALLOC, GC_MALLOC_ATOMIC, GC_REALLOC, GC_FREE, andGC_REGISTER_FINALIZER are also provided.  These require the same argumentsas the corresponding (nondebugging) routines.  If gc.h is includedwith GC_DEBUG defined, they call the debugging versions of thesefunctions, passing the current file name and line number as the twoextra arguments, where appropriate.  If gc.h is included without GC_DEBUGdefined, then all these macros will instead be defined to their nondebuggingequivalents.  (GC_REGISTER_FINALIZER is necessary, since pointers toobjects with debugging information are really pointers to a displacementof 16 bytes form the object beginning, and some translation is necessarywhen finalization routines are invoked.  For details, about what's storedin the header, see the definition of the type oh in debug_malloc.c)INCREMENTAL/GENERATIONAL COLLECTION:The collector normally interrupts client code for the duration of a garbage collection mark phase.  This may be unacceptable if interactiveresponse is needed for programs with large heaps.  The collectorcan also run in a "generational" mode, in which it usually attempts tocollect only objects allocated since the last garbage collection.Furthermore, in this mode, garbage collections run mostly incrementally,with a small amount of work performed in response to each of a large number ofGC_malloc requests.This mode is enabled by a call to GC_enable_incremental().Incremental and generational collection is effective in reducingpause times only if the collector has some way to tell which objectsor pages have been recently modified.  The collector uses two sourcesof information:1. Information provided by the VM system.  This may be provided inone of several forms.  Under Solaris 2.X (and potentially under othersimilar systems) information on dirty pages can be read from the/proc file system.  Under other systems (currently SunOS4.X) it ispossible to write-protect the heap, and catch the resulting faults.On these systems we require that system calls writing to the heap(other than read) be handled specially by client code.See os_dep.c for details.2. Information supplied by the programmer.  We define "stubborn"objects to be objects that are rarely changed.  Such an objectcan be allocated (and enabled for writing) with GC_malloc_stubborn.Once it has been initialized, the collector should be informed witha call to GC_end_stubborn_change.  Subsequent writes that storepointers into the object must be preceded by a call toGC_change_stubborn.This mechanism performs best for objects that are written only forinitialization, and such that only one stubborn object is writableat once.  It is typically not worth using for short-livedobjects.  Stubborn objects are treated less efficiently than pointerfree(atomic) objects.A rough rule of thumb is that, in the absence of VM information, garbagecollection pauses are proportional to the amount of pointerful storageplus the amount of modified "stubborn" storage that is reachable duringthe collection.  Initial allocation of stubborn objects takes longer than allocationof other objects, since other data structures need to be maintained.We recommend against random use of stubborn objects in clientcode, since bugs caused by inappropriate writes to stubborn objectsare likely to be very infrequently observed and hard to trace.  However, their use may be appropriate in a few carefully writtenlibrary routines that do not make the objects themselves availablefor writing by client code.BUGS:  Any memory that does not have a recognizable pointer to it will bereclaimed.  Exclusive-or'ing forward and backward links in a listdoesn't cut it.  Some C optimizers may lose the last undisguised pointer to a memoryobject as a consequence of clever optimizations.  This has almostnever been observed in practice.  Send mail to boehm@acm.orgfor suggestions on how to fix your compiler.  This is not a real-time collector.  In the standard configuration,percentage of time required for collection should be constant acrossheap sizes.  But collection pauses will increase for larger heaps.They will decrease with the number of processors if parallel markingis enabled.(On 2007 vintage machines, GC times may be on the order of 5 msecsper MB of accessible memory that needs to be scanned and processor.Your mileage may vary.)  The incremental/generational collection facilitymay help in some cases.  Please address bug reports to boehm@acm.org.  If you arecontemplating a major addition, you might also send mail to ask whetherit's already been done (or whether we tried and discarded it).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -