[openbeos] Re: Pointer or reference?

  • From: "Scott MacMaster" <scott@xxxxxxxxxxxxxxxxxx>
  • To: <openbeos@xxxxxxxxxxxxx>
  • Date: Thu, 1 Apr 2004 21:41:50 -0500

This is actually an exampled of ownership.  Depending on your point of view
it could be a shared ownership between the objects that are sharing the data
or the owner is the framework code for managing the reference count and the
acquire/release mechanism.


Later,
Scott MacMaster

----- Original Message ----- 
From: "Bruno van Dooren" <bruno_van_dooren@xxxxxxxxxxx>
To: <openbeos@xxxxxxxxxxxxx>
Sent: Thursday, April 01, 2004 2:54 AM
Subject: [openbeos] Re: Pointer or reference?


>
> > Right, the owner should take care of deleting it's children.  If an
object
> > deletes itself then that applies that the object is the owner of itself.
> In
> > c++ programs this is never.  Thus an object in c++ should never delete
> > itself.
>
> not true. i have written code in which 1 thread can create an object that
is
> used by different threads
> afterwards. it is possible that the thread that has created the object no
> longer needs the object, but it can't be
> safely deleted until everyone is finished using it.
>
> to solve this problem, all classes that can be used this way derive from a
> class 'ManagedResource'. all ManagedResource objects are managed by a
> ResourceManager that tracks the objects usage through a usage counter.
every
> thread using the object raises the counter when it first acquires
possession
> of the pointer.
>
> when the object is 'released' by the thread, the resource counter is
> decremented again. the object is only deleted when the resource is marked
as
> unused.
>
> all this is implemented in a threadsafe way, and i have never had any
> problems with it so far.
>
> this algorithm is similar to the COM resource tracking algorithm.
>
> kind regards,
>     Bruno.
>
>
>


Other related posts: