I tried a little brut test about smart pointer from osg and the similar approch in boost with instrusive_ptr
here the result with the source code:

PROFILE_ROOT prt 100.00 glb 100.00 - time 31.785504 avg 31.785504 ncall 1 osg_sm prt 2.85 glb 2.85 - time 0.905553 avg 0.905553 ncall 1 boost_sm prt 2.84 glb 2.84 - time 0.901856 avg 0.901856 ncall 1 boost2 prt 23.95 glb 23.95 - time 7.611869 avg 7.611869 ncall 1 osg2 prt 70.37 glb 70.37 - time 22.366193 avg 22.366193 ncall 1
Cedric

Robert Osfield wrote:
Hi André,

On 8/31/07, André Garneau <[EMAIL PROTECTED]> wrote:
FYI you might want to check the Boost::intrusive_ptr implementation (similar
in concept to OSG's ref_ptr) as it is using an underlying implementation
that does atomic reference counting (using CPU native Interlocked
test/increments). Note that I'm not suggesting to use Boost, just to get
ideas from this implementation.

Thanks for the suggestion.

I'm chasing bugs right now.  Could members of the community have a
look into this? i.e. the possibility of adding atmoic counts into
OpenThreads and ref_ptr<>.

Cheers,
Robert.
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
/*
#
# Copyright (C) 2007 Cedric Pinson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors:
#  Cedric Pinson <[EMAIL PROTECTED]>
#
# 
*/
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include <iostream>

#ifdef USE_NPROFILE
#include <nprofile/profile.h>
#endif

#include <cstdlib>
#include <osg/Referenced>
#include <osg/ref_ptr>

#include <cmath>

#include <boost/config.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/intrusive_ptr.hpp>



struct Test : public osg::Referenced
{
protected:
public:
  int value;
  Test(): value(1) {}
  void test1() { value+=1;}
  void test2()  { value+=2;}
};

struct TestBoost
{
  unsigned int count;

  TestBoost(): count(0)
  {
    value = 1;
  }

  int value;
  void test1() { value+= 1;}
  void test2()  { value+=2;}

};

void intrusive_ptr_add_ref(TestBoost * p)
{
  ++p->count;
}

void intrusive_ptr_release(TestBoost * p)
{
  if(--p->count == 0) delete p;
}



static boost::intrusive_ptr<TestBoost> test_boost= new TestBoost;
static osg::ref_ptr<Test> test_osg = new Test;

void testboost(int n)
{
  NPROFILE_SAMPLE("boost_sm");
  for (int i = 0;i < n; i++) {
  for (int j = 0;j < n; j++) {
    test_boost->test1();
    test_boost->test2();
    test_boost->test1();
    test_boost->test2();
    test_boost->test1();
    test_boost->test2();
  }
  }
}

void testboost2(int n)
{
  NPROFILE_SAMPLE("boost2");
  for (int i = 0;i < n; i++) {
    boost::intrusive_ptr<TestBoost> test_boost2;
    boost::intrusive_ptr<TestBoost> test_boost3;
    test_boost2 = test_boost;
    test_boost3 = test_boost2;
    test_boost = test_boost3;
  }
}

void testosg(int n)
{
  NPROFILE_SAMPLE("osg_sm");
  for (int i = 0;i < n; i++) {
  for (int j = 0;j < n; j++) {
    test_osg->test1();
    test_osg->test2();
    test_osg->test1();
    test_osg->test2();
    test_osg->test1();
    test_osg->test2();
  }
  }
}

void testosg2(int n)
{
  NPROFILE_SAMPLE("osg2");
  for (int i = 0;i < n; i++) {
    osg::ref_ptr<Test> test_osg2;
    osg::ref_ptr<Test> test_osg3;
    test_osg2 = test_osg;
    test_osg3 = test_osg2;
    test_osg = test_osg3;
  }
}

void func(int arg)
{
  //  NPROFILE_SAMPLE("root");
  testosg(arg);
  testboost(arg);
  testboost2(arg);
  testosg2(arg);
}

int main(int argc , char **argv)
{

  unsigned int arg = 2147483647;
  std::cout << arg << std::endl;

  nprf::GetProfiler()->Reset();

  func(arg);

  nprf::GetProfiler()->EndProfile();
  nprf::GetProfiler()->GetRootNode()->DisplayFlatStats(std::cout);
  std::cout << test_osg->value << std::endl;
  std::cout << test_boost->value << std::endl;

  return 0;
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to