Boost logo

Boost :

From: Achilleas Margaritis (axilmar_at_[hidden])
Date: 2006-05-21 20:33:22


> [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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk