Setjmp
Setjmp

Reputation: 28372

sample code or projects using simple reference counter in C

I am wondering how difficult it would be to integrate a reference counting (or other managed memory) regime for managing some of my struct libraries in C. What sample code would you recommend I look at?

Upvotes: 4

Views: 641

Answers (3)

tsg
tsg

Reputation: 2041

XMLRPC-c and json-c are examples of C libraries that use reference counting (and have slightly different approaches as to when to increment them behind the scenes) . If you are in a multi-threaded environment, you might also be interested in the kref usage in the Linux kernel.

Upvotes: 2

Aaron Digulla
Aaron Digulla

Reputation: 328624

Python uses garbage collection based on RC and it also solves the circular reference problem (i.e. when you have two or more objects that reference each other but no one else references them; in this case, the ref count will be > 0 but the whole cycle could be collected).

Upvotes: 2

jdehaan
jdehaan

Reputation: 19938

This garbage collector is widely used for C (even in gcc)

Upvotes: 2

Related Questions