Jump to content
  • Advertisement
Sign in to follow this  
load_bitmap_file

Unity shared_ptr overheads?

This topic is 5473 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does boost::shared_ptr have any overheads over raw pointers and auto_ptr? I tried googling, and checking the documentation but I couldn't find what I wanted. A poster at this thread said that after swapping out raw pointers with shared_ptr in his code his program execution speed rose noticeably. I'm going to need shared_ptr for RAII which is why I am asking.

Share this post


Link to post
Share on other sites
Advertisement
I don't get your question here. It is all in the thread you referred to:

auto_ptr + shared_ptr: 1 inc at construction, 1 additional ptr lookup per ptr deref, 1 dec if you release the pointer
shared_ptr: 1 inc + 1 dec for copying of the pointer (reference counting)

I think thats it.

Thermo/Konfu

Share this post


Link to post
Share on other sites
I don't know enough to talk about it much, but there is likely a cache miss as well, since the ref count is probably elsewhere in memory.

Share this post


Link to post
Share on other sites
Quote:
Original post by load_bitmap_file
Does boost::shared_ptr have any overheads over raw pointers and auto_ptr? I tried googling, and checking the documentation but I couldn't find what I wanted.


for one std::auto_ptr is not equilavant to boost::shared_ptr, they serve different purposes/needs (although boost::shared_ptr can be used to replace everything auto_ptr can do), boost::scoped_ptr is equilavant to std::auto_ptr how-ever.

The functionality of boost::shared_ptr far out-weight that little minor overhead besides if your using boost::shared_ptr with STL containers you can use boost's pool allocator with it instead of the default allocator if you really do find any overheads. Over-head comes from the reference counting which boost::scoped_ptr & boost::scoped_array don't have (i think!).

Quote:
Original post by load_bitmap_file
I'm going to need shared_ptr for RAII which is why I am asking.


you don't need boost::shared_ptr just for that, you can use boost::scoped_ptr and boost::scoped_array for RAII techniques.

Share this post


Link to post
Share on other sites
Quote:
Original post by snk_kid
boost::scoped_ptr is equilavant to std::auto_ptr how-ever.

To be pedantic: They aren't really equivalent, std::auto_ptr is assignable and can be used as return value for functions, where as boost::scoped_ptr isn't assignable and can't be used as return value for functions.

Share this post


Link to post
Share on other sites
Quote:
Original post by dalleboy
Quote:
Original post by snk_kid
boost::scoped_ptr is equilavant to std::auto_ptr how-ever.

To be pedantic: They aren't really equivalent, std::auto_ptr is assignable and can be used as return value for functions, where as boost::scoped_ptr isn't assignable and can't be used as return value for functions.



Perhaps i should have been more clear, i mean't conceptually there equilavant in terms of there use, they are both mainly used to implement RAII nothing more.

I would say that scoped_ptr has more in common than shared_ptr does with auto_ptr.

Quote:
Original post by load_bitmap_file
shared_ptr does have some overhead but it's extremely small and thus negligible, correct?


For its intended purpose yes.

Share this post


Link to post
Share on other sites
Quote:
Original post by snk_kid
Quote:
Original post by load_bitmap_file
shared_ptr does have some overhead but it's extremely small and thus negligible, correct?


For its intended purpose yes.


Thanks snk_kid and everyone else who replied!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!