Boost logo

Boost :

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


> 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


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