Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2001-05-11 06:20:13


John Max Skaller wrote:

> Larry Evans wrote:
> http://groups.yahoo.com/group/boost/files/GarbageCollectByTmplSpecializa/gc_sel_ssp.zip
> > > > in directories below the directory lib/gc_sel_ssp/tests/drivers.
> > >
> > > OK, I'll have a look. HMMM:
> > > ---------------------------------------------
> > > make usage
> > > : No such file or directory
> > > : No such file or directory.imk
> > > : No such file or directory/tests/drivers/crc
> > > Makefile:26: *** missing separator. Stop.
> > > -----------------------------------------
> > > Just try 'make':
> > > -----------------------------------------
> > > root_at_pelican] ~/gcsel>make
> > > : No such file or directory
> > > : No such file or directory.imk
> > > : No such file or directory/tests/drivers/crc
> > > Makefile:26: *** missing separator. Stop.
> > > -----------------------------------------
> >
> > OOPS. Are you using gnu make?
>
> Is there anything else on linux? :-)

OOPS. I forgot to tell you to read the README file, 3ird paragraph
from bottom. The above errors are caused by CR in the Makefile.

>
>
> > > What I'd like to see is a simple example, not a test routine.
> > > For example: how would I make a singly linked list of 10 integers?
> >
> > My "gc_sel_ssp" method can't do integers.
>
> I said a _linked list of integers_. That is, you'd
> derive the _link node_ from something (not integers :-)

The following should work:
----------------------
template
  < typename SubjTop
  , off_root OffRoot=root_prox
>
  class
SubjIntVec
  : public subj_offroot<SubjTop,OffRoot>
  , public vector<int>
  {
  public:
        typedef
      subj_offroot<SubjTop,OffRoot>
    subj_super_type
      ;
        virtual
      offsets_subj_proxies const&
    get_offsets(void)const
      //return the offsets to proxies contained by this subject.
      { return offsets_subj_proxies::emptyOffsets()
      ;}
    //the following code is needed to compile the Subj1__TEST
    //in the main.cpp test driver.
    operator
      SubjIntVec<SubjTop,off_no>&
      (void)
      { return static_cast<SubjIntVec<SubjTop,off_no>&>(as_off_no())
      ;}
    operator
      SubjIntVec<SubjTop,off_no>const&
      (void)const
      { return static_cast<SubjIntVec<SubjTop,off_no>const&>(as_off_no())
      ;}

   };
-------------------------------
Then instantiate it with either of the SubjTop template classes:
    subjtop_lazy_crc
    subjtop_simpmsw__zomsafe__
Headers for both of these classes are found subdirectories of
boost/gc_sel_ssp/special. You create a smart pointer to the above by:
--------------------------------
  prox_btm<SubjIntVec,subjtop_lazy_crc> sp_crc;
  prox_own_btm<SubjIntVec,subjtop_simpmsw__zomsafe__> sp_zomsafe;
--------------------------------
The prox_own_btm diagnoses dangling pointers, as explained in the
documentation you've read.

...skipping

> > > One possible solution is to use a class I haven't provided
> > > yet: root_handle. This 'reference counts' its argument, by adding
> > > it as a root on acquisition, and decrementing the root
> > > count on release. The root_handle doesn't need to be swept
> >
> > I don't understand. I'm thinking you mean root_handle store's a pointer
> > to itself in a set of roots (i.e. add it as root on acquisition).
>
> No, it stores the pointer it _manages_ into the
> set of roots. But I use an STL map:
>
> pointer -> count
>
> for roots now, so you can add the same pointer 10 times,
> then remove it 9 times and it is still a root.

That uses less memory (after all, there are fewer pointee's than pointers);
however, wouldn't this require an O(log(V.size)) lookup each time the
root_handle is assigned?

...skipping

> use it. So want instructions like:
>
> To use my system,
>
> 1. DO this.
> 2. Now do this.
> 3. Finally, do this.
>
> with examples. I don't want to think or learn. :-)
>

1) Decide which garbage collection method, i.e. which subjtop class)
     you want, say subjtop_mine.
2) Given some class, SomeClass, which you want to gc, modify it by
     adding:
       2.1) 2 template parameters:
               2.1.1) the gc method parameter, SubjTop.
               2.1.2) the off_root parameter, OffRoot.
       2.2) a typedef for subj_super_type
       2.3) a virtual get_offsets(void)const method:
             If (SomeClass does not contain any prox* classes)
                {
                ; return offsets_subj_proxies::emptyOffsets() from get_offsets
                ;}
             else
                {
                ; return mk_off_yes<SomeClass<SubjTop,off_yes> >::offsets()
                ; for each member variable, m_var of type, MemClass, declare it as:
                     prox_btm<MemClass,SubjTop,OffRoot> m_var;
                   where MemClass has been similarly modified.
                ; provide a definition of the class variable using the gc method
                  selected in step 1):
                      mk_off_yes<SomeClass<subjtop_mine,off_yes> >::c_offsets
                ;}
 3) Create smart pointers for SomeClass by, for example:
       3.1) if you want dangling pointer diagnosis:
                3.1.1) for owning pointer:
                            prox_own_btm<SomeClass,subjtop_mine> prox_own_SomeClass;
                3.1.2) for using pointer:
                            prox_use_btm<SomeClass, subjtop_mine> prox_use_SomeClass;
       3.2) otherwise:
                prox_btm<SomeClass,subjtop_mine> prox_SomeClass;

For example:
---------------------------
template
  < typename SubjTop
  , off_root OffRoot=root_prox
>
  class
SomeClass
  : public subj_offroot<SubjTop,OffRoot>
  //...other superclasses
  {
  public:
        typedef
      subj_offroot<SubjTop,OffRoot>
    subj_super_type
      ;
        virtual
      offsets_subj_proxies const&
    get_offsets(void)const
      //return the offsets to proxies contained by this subject.
      { return mk_off_yes<SomeClass<SubjTop,off_yes> >::offsets()
      ;}
      prox_btm<OtherClass,SubjTop,OffRoot>
    m_contained_prox
      ;
  };
  mk_off_yes<SomeClass<subjtop_mine,off_yes> >
mk_off_yes<SomeClass<subjtop_mine,off_yes> >::c_offsets
  ;
-----------------------------------
Of course I'd appreciate any suggestions for making these
instructions clearer.


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