2

I've started by using reference counting in my library I'm making. It's a pretty decent solution and the increments and decrements don't waste many resources as some people wrongly seem to think. Also the slight extra memory for reference counts is negligible.

But apparently tracing garbage collection is so good that it is better than using malloc/free. I'm not sure if this is true so I'd like to try it out (Back-end optimisations by freeing multiple objects at once?). Also GC would make my library easier to use, as calling retain/release functions is not needed.

Edit: The problem is that gc/gc.h includes itself infinitely. This makes no sense...

Thanks.

Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122
  • It's not true, though some GC zealots will claim it is. GC is fundamentally incompatible with C. See http://stackoverflow.com/questions/4039274/was-there-a-specific-reason-garbage-collection-was-not-designed-for-c/4039474#4039474 – R.. GitHub STOP HELPING ICE May 21 '12 at 01:04
  • gc is competitive with handroll only when gc has vastly more virtual address space to play with than your app ever has in use at a time, and either any reasonable overhead doesn't matter anyway (which it doesn't, in the vast majority of cases) or you're careful about reference patterns. – jthill May 21 '12 at 01:28
  • By the way, I'm pretty sure a dependency on Boehm GC would not make your library "easier to use", since it would completely preclude using your library in any application that needs to be robust. – R.. GitHub STOP HELPING ICE May 21 '12 at 01:31
  • Is the header gc.h installed in /usr/local/include? The directory /usr/local/include should be in GCC's default search path for headers so it should be able to find it without any additional options.Perhaps you can supply some more information as to how you are compiling and linking your library? – Rich Drummond May 21 '12 at 03:04
  • Thanks Rich. Was imaging the dylib to be like a framework which (from what I remember) includes header files. I got the header files into place but there is an infinite include recursion with gc/gc.h which makes no sense... – Matthew Mitchell May 21 '12 at 16:44
  • 1
    Also thanks R. The vulnerability that could cause memory leaks might be an issue if an attack is practical when receiving information from a network? – Matthew Mitchell May 21 '12 at 16:51
  • So did you install the headers manually? If so, it's possible you made a mistake when doing this. Issuing 'sudo make install' will install everything (dylib and headers) in the correct places for you automatically. – Rich Drummond May 22 '12 at 15:57

1 Answers1

0

The question is rather vague. do you want to know how to use libgc in general or do you want to know how to get it working on mac OS X? if later is the case then I recommend using Homebrew. It has a pretty decent formula for libgc. just use the command:

brew install libgc

this will install the library in /usr/local/Cellar/libgc/7.6.0 depending on the latest version available in HomeBrew formula.

the confusion you have regarding gc.h referring to itself infinitively is actually not true. because there is another gc.h in the gc subfolder which the first gc.h is including. I have no idea why they have designed it like this though!

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193