On Thu, Mar 12, 2009 at 3:55 PM, Dirk Reiners <[email protected]> wrote:
> Allen Bierbaum wrote:
>> How do you keep a weak pointer across threads? Is there an MTWeakPtr
>> or equivalent (haven't seen it so far).
>
> Hasn't come up yet as a need.

The place I need it is for a global geometry factory.

I have a system that basically looks something like this:

class Factory:
   std:map<style, OSG::ChunkMaterialXXX> style cache;

   OSG::NodeMTRecPtr  buildGeomNode(myGeom* geom, Style style);

I want to cache the style materials across multiple built geometries.
But once the last geometry using that cached style is removed, I don't
want to hold onto the material any more.  Until this morning I didn't
think I would be able to do this, but now I think I could do it with
an MTWeakPtr.  (I need MT because this can be called from multiple
threads)

> Should be pretty easy to do though, just add a
>
>
> struct MTWeakRefCountPolicy : public WeakRefCountPolicy
> {
>     template <class T>
>     static T *validate   (T *pObject)
>     {
>         return convertToCurrentAspect(pObject);
>     }
>
>     template <class T>
>     static T &dereference(T *pObject)
>     {
>         return *(validate(pObject));
>     }
> };
>
> and use it. Or am I too optimistic here?

So, where exactly would I add this in the OpenSG code?  Also, where
should I put the ptr type aliases?

-Allen

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to