Is there interest for a small portable garbage collection library?

Dear boost developers, Is there any interest for a small portable garbage collection library? I have written such a library to use for my personal projects and I would like to share it with the community, as I think it is very helpful in developing certain kinds of applications. Features: -small (under 2000 LOC) -portable (no lowlevel OS/CPU/compiler-specific features) -precise mark & sweep collection -no dependencies; headers only -weak pointers -garbage-collected arrays -customizable collector with user-defined finalizer and mark functions -wrapper class for external non-garbage-collected classes -thread-based collection "Thread-based collection" means the library can only support thread-specific collectors. I did not want to introduce dependencies on specific threading libraries, as they vary from project to project (and if many threads compete for the same collector, applications tend to slow down). The library, as it is, provides a collector for the main thread, but the function that returns the current collector can be modified to return a thread-specific collector (using thread-specific-storage). I have posted an article on www.codeproject.com about it along with the source code, code documentation and unit tests. It can be found here: http://www.codeproject.com/useritems/libgc.asp I have also posted a file release on sourceforge: http://sourceforge.net/projects/libgc I have tested the code (so far) in vc++ 7.1, but I think it will work on GCC and other compilers, as it does not use any O/S-specific and compiler-specific features. Even if boost devs find no value in it, I would appreciate any feedback. Thanks a lot for your attention. Achilleas Margaritis

On 05/20/2006 07:28 AM, Achilleas Margaritis wrote:
Dear boost developers,
Is there any interest for a small portable garbage collection library?
Yes. [snip]
Features:
-small (under 2000 LOC) -portable (no lowlevel OS/CPU/compiler-specific features) -precise mark & sweep collection
How is the precision achieved without compiler support?
-no dependencies; headers only -weak pointers -garbage-collected arrays
Why are array specifically mentioned? Does this mean they have to be declared as garbage collected? [snip]
I have posted an article on www.codeproject.com about it along with the source code, code documentation and unit tests. It can be found here:
http://www.codeproject.com/useritems/libgc.asp [snip] Even if boost devs find no value in it, I would appreciate any feedback.
I'll probably have some as soon as I can read and understand the above link. Meanwhile, you might want to compare it with the precise collector in the policy_ptr library in boost sandbox. The test for a precise collector (as well as conservative and flawed [w.r.t. stl container or most any container with dynamic allocatio]) is here: http://tinyurl.com/njce2 the precise collector is the one tested with the: test_adder.add_spid<std_shared_graph_accepting>(); statements. I know it's hard to decipher the code, but I haven't got around to documenting it yet. Besides, I'm in the midst of rewriting the whole "backbone" of the precise collector. This backbone simply allows enumeration of selected "fields" of any class. The selected fields, in the case of the precise collector, are those smart_ptr's that are: std_ptr<T>::shared_accepting; which is defined here: http://tinyurl.com/fyzoc the "backbone" was in the boost sandbox under fields_visitor; however, as mentioned, I'm refactoring it in response to feedback from David Abrahams in the post: http://archives.free.net.ph/message/20060125.200646.b14e2a82.en.html Anyway, I'll get back to you with more feedback. Thanks for the another alternative gc look look at and learn from. -regards, Larry

How is the precision achieved without compiler support?
The class 'ptr' (used for global and stack pointers) pushes itself in the current collector's stack on construction and removes itself from that stack on destruction. Example: ptr<Foo> ptr1 = new Foo; The class 'member_ptr' is registered to the owner object in the owner object's constructor. Example: class Foo : public object { member_ptr<Foo> next; Foo() : next(this) { } }; The above is one of the available strategies. The library allows custom mark strategies to be implemented so as that member_ptrs need not be used. For example: class node { public: node *prev; node *next; void *operator new(size_t size, temp_ptr &tmp = temp_ptr) { return get_garbage_collector().malloc(size, 0, &mark, 0, tmp); } static void mark(void *p) { node *n = (node *)p; get_garbage_collector().mark(node->prev); get_garbage_collector().mark(node->next); } };
Why are array specifically mentioned? Does this mean they have to be declared as garbage collected?
Yes. Arrays are declared like this: ptr<array<Foo> > array1 = new array<Foo>[10]; The reason is that I needed to specify 'operator new' for arrays.
I'll probably have some as soon as I can read and understand the above link. Meanwhile, you might want to compare it with the precise collector in the policy_ptr library in boost sandbox.
Thanks a lot. I will check it out. Achilleas

On 05/20/2006 12:25 PM, Achilleas Margaritis wrote:
How is the precision achieved without compiler support?
The class 'ptr' (used for global and stack pointers) pushes itself in the current collector's stack on construction and removes itself from that stack on destruction. Example:
ptr<Foo> ptr1 = new Foo;
The class 'member_ptr' is registered to the owner object in the owner object's constructor. Example:
class Foo : public object { member_ptr<Foo> next; Foo() : next(this) { } };
[snip] If Foo is on the stack, is Foo::next pushed on current collector's stack? If std::vector<Foo> is on the stack, are all it's contained Foo::next's pushed on the current collector's stack?

[snip] If Foo is on the stack, is Foo::next pushed on current collector's stack? If std::vector<Foo> is on the stack, are all it's contained Foo::next's pushed on the current collector's stack?
I was going to reply with a 'no' (i.e. if Foo is on the stack then Foo::next is not pushed in the current collector's stack), when I realized the many problems that will be created by that. So I went and redesigned the library, and now the following are possible: 1) declaring garbage-collected objects either on the heap or on the stack. 2) declaring garbage-collected arrays either on the heap or on the stack. 3) allocating garbage-collected arrays of objects (not pointers of objects, arrays of objects). 4) having garbage-collected pointers point to members of garbage-collected objects that are not pointers. In other words, the following is possible: class bar : public object { }; class foo : public object { ptr<foo> next; bar bar1; }; ptr<foo> foo1 = new foo; ptr<foo> foo2 = new foo[10]; ptr<foo> foo3[10]; foo3[5] = foo2 + 3; ptr<ptr<foo> > ptr1 = new ptr<foo>; *ptr1 = foo3[5]; foo1->next = new foo[10]; ptr1 = new ptr<foo>[10]; ptr<bar> bar1 = &foo1->bar1; Now coding is similar to normal c++ coding but with these exceptions: a) the programmer needs to use 'ptr' or 'weak_ptr' class either as a member or a stack pointer. b) garbage collected objects should inherit from 'object'. The collector provides per memory block policies for managing finalization and marking. I have posted the new implementation in the vault, under memory; the library is complete except for weak_ptr (but the infrastructure is completed, and adding weak_ptr is easy). As always, discussion and analysis are welcomed. Achilleas

It seems there is not interest for such a library after all. Anyway, I placed the final beta version in the vault under memory. The only library it uses is pthreads, so it should be portable (I have tested it on msvc++ 7 so far). A reminder of capabilities: 1) portability. 2) uses pthreads. 3) critical section locking is done per thread (so as that the number of threads does not affect the allocation performance) 4) objects can be allocated on the heap or on the stack. 5) objects can be arrays. 6) gc ptrs can point in the middle of objects. 7) it is precise. Disadvantages: Not very fast, since each pointer has to find out if it belongs in the heap or on the stack and register itself to the appropriate collection. But anyway it should be good for projects that do not have big performance requirements.

Achilleas Margaritis wrote:
It seems there is not interest for such a library after all. Anyway, I placed the final beta version in the vault under memory. The only library it uses is pthreads, so it should be portable (I have tested it on msvc++ 7 so far).
Your problem in gaining interest is that your documentation does not explain the use of your library. This is a common mistake of many programmers, who put out implementations and assume that anyone interested must be willing to spend hours or days figuring out, somehow, what is there and how it is to be used. Inevitably, no matter how original or creative that implementation may be, it will be unused by the vast majority of people who, given adequate documentation, might be interested in it. Take a look at the Boost documentation for its libraries to see what should be done to explain the use of yours. Then, if you update your documentation and explain well what your library does and how the end user should use it in its main use cases, I believe you will garner some interest by potential users.

Your problem in gaining interest is that your documentation does not explain the use of your library. This is a common mistake of many programmers, who put out implementations and assume that anyone interested must be willing to spend hours or days figuring out, somehow, what is there and how it is to be used. Inevitably, no matter how original or creative that implementation may be, it will be unused by the vast majority of people who, given adequate documentation, might be interested in it.
Take a look at the Boost documentation for its libraries to see what should be done to explain the use of yours. Then, if you update your documentation and explain well what your library does and how the end user should use it in its main use cases, I believe you will garner some interest by potential users.
Thanks a lot for the advice. That is what I am going to do.
participants (4)
-
Achilleas Margaritis
-
Achilleas Margaritis
-
Edward Diener
-
Larry Evans