Is scoped_ptr excessive in simple cases?

I use scoped_ptr inside small functions like this. so I do not need to call delete. Is there an excess for this use? My team members prefer rude pointers and delete. What is the cost of using scoped_ptr if it is used for a very critical path? Shouldn't it be aligned and exactly equivalent to simply using regular deletion in an optimized binary?

void myfunc()
{
  boost::scoped_ptr<myobj> objptr = someFactory::allocate();
  callsomeotherfunc(objptr.get());
}
+5
source share
4 answers

, scoped_ptr myfunc() : if callsomeotherfunc() , . scoped_ptr , callsomeotherfunc() , :

void myfunc()
{
    myobj* objptr = someFactory::allocate();

    try
    {
        callsomeotherfunc(objptr);
        delete objptr;
    }
    catch (const some_exception&)
    {
        delete objptr;
        throw;
    }
}

, , delete objptr; .

+8

scoped_ptr , unique_ptr ++ 11 auto_ptr , . , , , , (, - myfunc, callsomeotherfunc throws, , ). , delete , , , try/catch delete, .

, , factory , factory deallocate, , delete. , (shared_ptr , , delete managed_ptr, )

+3

, . (, ) CPU , , .

0

, scoped_ptr :

void myfunc()
{
  myobj* objptr = someFactory::allocate();
  try
  {
      callsomeotherfunc(objptr);
  }
  catch (...)
  {
      delete objptr;
      throw;
  }
  delete objptr;
}

, ...

0
source

All Articles