World Library  
Flag as Inappropriate
Email this Article
 

Boehm garbage collector

Boehm–Demers–Weiser Garbage Collector
Written in C and C++
Type garbage collector
License similar to X11 (free software)
Website http://www.hboehm.info/gc/

In computer science, the Boehm–Demers–Weiser garbage collector, often simply known as Boehm GC, is a conservative garbage collector for C and C++.[1]

Boehm GC is free software distributed under a permissive free software licence similar to the X11 license.

Contents

  • Design 1
  • Operation 2
  • Uses and ports 3
  • References 4
  • External links 5

Design

The developer describes the operation of the collector as follows:

Boehm GC can also run in leak detection mode[2] in which memory management is still done manually, but the Boehm GC can check if it is done properly. In this way a programmer can find memory leaks and double deallocations.

Boehm GC is also distributed with a C string handling library called cords. This is similar to ropes in C++ (strings are trees of small arrays, and they never change), but instead of using reference counting for proper deallocation, it relies on garbage collection to free objects. Cords are good at handling very large texts, modifications to them in the middle, slicing, concatenating, and keeping history of changes (undo/redo functionality).

Operation

The garbage collector works with most unmodified C programs, simply by replacing malloc() with GC_MALLOC() calls, replacing realloc() with GC_REALLOC() calls, and removing free() calls.[1] The code piece below shows how one can use Boehm instead of traditional malloc and free in C.[3]

#include 
#include 
#include 

int main(void)
{
    int i;

    GC_INIT();
    for (i = 0; i < 10000000; ++i)
    {
        int **p = (int**)GC_MALLOC(sizeof(int *));
        int *q = (int*)GC_MALLOC_ATOMIC(sizeof(int));

        assert(*p == 0);
        *p = (int*)GC_REALLOC(q, 2 * sizeof(int));
        if (i % 100000 == 0)
            printf("Heap size = %zu\n", GC_get_heap_size());
    }

    return 0;
}

Uses and ports

The Boehm GC is used by many projects that are implemented in C or C++ like Inkscape, as well as by runtime environments for a number of other languages, including the GNU Compiler for Java runtime environment, the Portable.NET project, Embeddable Common Lisp, GNU Guile, the Mono implementation of the Microsoft .NET platform (also using precise compacting GC since version 2.8), and libgc-d (a binding to libgc for the D programming language, used primarily in the MCI). It supports numerous operating systems, including many Unix variants (such as Mac OS X) and Microsoft Windows, and provides a number of advanced features including incremental collection, parallel collection and a variety of finalizer semantics.

References

  1. ^ a b Koranne, Sandeep (2011), Handbook of Open Source Tools, Springer, pp. 151–154,  
  2. ^ Using the Garbage Collector as Leak Detector
  3. ^ Using the Garbage Collector: A simple example

External links

  • Homepage
  • Boehm garbage collector on SourceForge.net
  • Git repo for BoehmGC development
  • Transparent Programmer-Directed Garbage Collection for C++, Hans-J. Boehm and Michael Spertus
  • Using the C/C++ Garbage Collection Library
  • Dr. Dobbs The Boehm Collector for C and C++, Gene Michael Stover, March 01, 2003
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.