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()); }
, scoped_ptr myfunc() : if callsomeotherfunc() , . scoped_ptr , callsomeotherfunc() , :
scoped_ptr
myfunc()
callsomeotherfunc()
void myfunc() { myobj* objptr = someFactory::allocate(); try { callsomeotherfunc(objptr); delete objptr; } catch (const some_exception&) { delete objptr; throw; } }
, , delete objptr; .
delete objptr;
scoped_ptr , unique_ptr ++ 11 auto_ptr , . , , , , (, - myfunc, callsomeotherfunc throws, , ). , delete , , , try/catch delete, .
unique_ptr
auto_ptr
myfunc
callsomeotherfunc
delete
try/catch
, , factory , factory deallocate, , delete. , (shared_ptr , , delete managed_ptr, )
deallocate
shared_ptr
managed_ptr
, . (, ) CPU , , .
, scoped_ptr :
void myfunc() { myobj* objptr = someFactory::allocate(); try { callsomeotherfunc(objptr); } catch (...) { delete objptr; throw; } delete objptr; }
, ...