[OT] Looking for garbage collection library

Discussion in 'C Programming' started by Philipp Klaus Krause, Oct 16, 2010.

  1. I'm looking for a garbage collection library, but have not been
    sucessfull so far.

    Requirements:

    - Written in C (and C only), I guess this requirement practically
    implies that the GC has to get memory via malloc() or just use a global
    array.

    - Is small

    - Works well with low amounts of memory, e.g. managing just half a KB or so.

    Has anyone come across such a library?

    Philipp
     
    Philipp Klaus Krause, Oct 16, 2010
    #1
    1. Advertising

  2. On 2010-10-16 18:57, Philipp Klaus Krause wrote:
    > I'm looking for a garbage collection library, but have not been
    > sucessfull so far.
    >
    > Requirements:
    >
    > - Written in C (and C only), I guess this requirement practically
    > implies that the GC has to get memory via malloc() or just use a global
    > array.
    >
    > - Is small
    >
    > - Works well with low amounts of memory, e.g. managing just half a KB or so.
    >
    > Has anyone come across such a library?


    Does libgc meet your requirements?

    http://www.hpl.hp.com/personal/Hans_Boehm/gc/


    /August

    --
    The competent programmer is fully aware of the limited size of his own
    skull. He therefore approaches his task with full humility, and avoids
    clever tricks like the plague. --Edsger Dijkstra
     
    August Karlstrom, Oct 16, 2010
    #2
    1. Advertising

  3. Philipp Klaus Krause, Oct 16, 2010
    #3
  4. Philipp Klaus Krause, Oct 16, 2010
    #4
  5. Philipp Klaus Krause wrote:

    > I'm looking for a garbage collection library, but have not been
    > sucessfull so far.
    >
    > Requirements:
    >
    > - Written in C (and C only), I guess this requirement practically
    > implies that the GC has to get memory via malloc() or just use a global
    > array.
    >
    > - Is small
    >
    > - Works well with low amounts of memory, e.g. managing just half a KB or
    > so.
    >
    > Has anyone come across such a library?


    I'm a bit puzzled here... What exactly do you expect it to do?
    If you simply want to have it "automagically" regain memory that
    has been malloc()ed, but not freed, albeit not being used any
    longer, and all this in already existing, pure C code, I'd say
    the reason why you haven't found such a GC is simply that there's
    no conceivable way to implement it.

    If you need a malloc()-Debugger that helps finding memory leaks,
    then that's a different story: electric fence, dmalloc, NJAMD, ...

    If you're looking for a solution where dynamically allocated
    memory will automatically be free()d upon leaving the function
    that requested it, then alloca() will be your friend.

    But a reliably working GC for plain C code? Uh-oh... ;)


    mike
     
    Michael Schumacher, Oct 16, 2010
    #5
  6. Philipp Klaus Krause

    Eric Sosman Guest

    On 10/16/2010 2:16 PM, Philipp Klaus Krause wrote:
    > Am 16.10.2010 20:08, schrieb August Karlstrom:
    >>
    >> Does libgc meet your requirements?
    >>
    >> http://www.hpl.hp.com/personal/Hans_Boehm/gc/

    >
    > No: "The collector inherently has to perform operations, [...], that are
    > not possible in portable C code. [...]


    This will probably be true of any garbage-collection scheme
    for full-fledged C. To determine whether a piece of memory is
    garbage, the GC needs to discover whether any "live" pointers aim
    at it or into it. Thus, it needs to examine all the places such
    pointers might live -- and the discovery and examination of all
    those places seems a highly non-portable task. Even if you assume
    that all memory blocks are referenced via actual pointers (and not
    via self-relative offsets, for example), I think you will find it
    difficult to locate all those pointers. For example, suppose that
    the only extant pointer to a block is an `auto' or `register'
    variable in a function six frames higher up the call stack; the
    task of examining that dormant function's local variables does not
    lend itself to a portable solution.

    There's reference counting, but you need a way to maintain the
    counters as pointers are written, overwritten, and rewritten. Just
    copying a pointer from one place to another, or passing one as a
    function argument, or stuffing it into a struct and then copying the
    entire struct -- all of these can create new references that you'd
    have to track as they went into and out of existence. You could ask
    the programmer to help by using explicit seize(p) and forget(p) calls,
    but that seems extremely error-prone. (If you trust the programmer
    to use seize/forget properly, you can probably live with something a
    good deal less complicated than full-blown GC.)

    It seems to me that you'll need to live with some amount of
    non-portability, or else limit yourself to a narrow subset of C and
    enforce strict coding conventions.

    Can you tell us more about the larger problem you're facing?

    --
    Eric Sosman
    lid
     
    Eric Sosman, Oct 16, 2010
    #6
  7. Am 16.10.2010 21:18, schrieb Eric Sosman:
    >
    > Can you tell us more about the larger problem you're facing?
    >


    I was wondering about Scheme to C translation. I had looked at some
    Scheme to C translators, but found them unsuitable for what I want to
    do. I wondered how much effort it would take to roll my own. Scheme has
    garbage collection and passes everything by reference. I hoped there
    would be some library I could use for the garbage collection.

    Philipp
     
    Philipp Klaus Krause, Oct 16, 2010
    #7
  8. Philipp Klaus Krause

    Ian Collins Guest

    On 10/17/10 10:30 AM, Philipp Klaus Krause wrote:
    > Am 16.10.2010 21:18, schrieb Eric Sosman:
    >>
    >> Can you tell us more about the larger problem you're facing?
    >>

    >
    > I was wondering about Scheme to C translation. I had looked at some
    > Scheme to C translators, but found them unsuitable for what I want to
    > do. I wondered how much effort it would take to roll my own. Scheme has
    > garbage collection and passes everything by reference. I hoped there
    > would be some library I could use for the garbage collection.


    There is, libgc is a library you could use for the garbage collection.
    It is probably the most widely used garbage collector for C and C++
    applications.

    --
    Ian Collins
     
    Ian Collins, Oct 16, 2010
    #8
  9. Philipp Klaus Krause

    Jon Guest

    "Ian Collins" <> wrote in message
    news:...
    > On 10/17/10 10:30 AM, Philipp Klaus Krause wrote:
    >> Am 16.10.2010 21:18, schrieb Eric Sosman:
    >>>
    >>> Can you tell us more about the larger problem you're facing?
    >>>

    >>
    >> I was wondering about Scheme to C translation. I had looked at some
    >> Scheme to C translators, but found them unsuitable for what I want to
    >> do. I wondered how much effort it would take to roll my own. Scheme
    >> has
    >> garbage collection and passes everything by reference. I hoped there
    >> would be some library I could use for the garbage collection.

    >
    > There is, libgc is a library you could use for the garbage collection.
    > It is probably the most widely used garbage collector for C and C++
    > applications.
    >


    I fail to see how garbage collection, a highly controversial topic and
    yet to become more controversial, is relevant in a ng that spews "what's
    on topic?!" threads.
     
    Jon, Oct 17, 2010
    #9
  10. Philipp Klaus Krause

    Jon Guest

    "Jon" <> wrote in message
    news:i9e1fb$3q6$-september.org...
    >
    > "Ian Collins" <> wrote in message
    > news:...
    >> On 10/17/10 10:30 AM, Philipp Klaus Krause wrote:
    >>> Am 16.10.2010 21:18, schrieb Eric Sosman:
    >>>>
    >>>> Can you tell us more about the larger problem you're facing?
    >>>>
    >>>
    >>> I was wondering about Scheme to C translation. I had looked at some
    >>> Scheme to C translators, but found them unsuitable for what I want to
    >>> do. I wondered how much effort it would take to roll my own. Scheme
    >>> has
    >>> garbage collection and passes everything by reference. I hoped there
    >>> would be some library I could use for the garbage collection.

    >>
    >> There is, libgc is a library you could use for the garbage collection.
    >> It is probably the most widely used garbage collector for C and C++
    >> applications.
    >>

    >
    > I fail to see how garbage collection, a highly controversial topic and
    > yet to become more controversial, is relevant in a ng that spews
    > "what's on topic?!" threads.


    I missed the [OT] lameness.
     
    Jon, Oct 17, 2010
    #10
  11. Am 16.10.2010 21:04, schrieb Michael Schumacher:
    >
    > I'm a bit puzzled here... What exactly do you expect it to do?
    > If you simply want to have it "automagically" regain memory that
    > has been malloc()ed, but not freed, albeit not being used any
    > longer, and all this in already existing, pure C code, I'd say
    > the reason why you haven't found such a GC is simply that there's
    > no conceivable way to implement it.


    I was wondering about Scheme to C translation. Scheme has garbage
    collection, thus it has to be handled somehow. I suppose that by
    restristing how and where the thing have have to be handled by garbage
    collection are stored it can be done in pure C.

    Philipp
     
    Philipp Klaus Krause, Oct 18, 2010
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laser Lu

    Garbage Collection and Manage Code?

    Laser Lu, Jan 26, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    746
    Gaurav Khanna [C# MVP]
    Jan 27, 2004
  2. Cheung, Jeffrey Jing-Yen
    Replies:
    3
    Views:
    1,588
    Cheung, Jeffrey Jing-Yen
    Jul 10, 2003
  3. Replies:
    1
    Views:
    468
    mrstephengross
    Jul 25, 2005
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    1,028
    Øyvind Isaksen
    May 18, 2007
  5. marcomaggi

    looking for a BIBOP garbage collector library

    marcomaggi, Jun 28, 2011, in forum: C Programming
    Replies:
    0
    Views:
    247
    marcomaggi
    Jun 28, 2011
Loading...

Share This Page