Smart pointer obligating heap allocation when not needed..what am I doing wrong?

Started by
9 comments, last by EddieV223 11 years, 1 month ago

Lol all this topic has gone way off course, if you're pointing to stack memory use a naked pointer, there isn't any reason to use a shared_ptr in this case. If you wanted to you could use a reference, but there isn't much benefit in that except some cleaner syntax, but then you can't null the reference if you needed to.

That works in trivial cases but is not useful advise for the general case. Just because something can be allocated on stack does not mean every instance you have to work with is allocated on the stack. I have frequently worked in systems where instances might have to be deleted by library function A, library function B, by the standard delete or not at all (because they are a static instance on the stack).

I was speaking specifically about the OP's case.

If this post or signature was helpful and/or constructive please give rep.

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

// Easy to learn 2D Game Library c++

SFML2.2 Download http://www.sfml-dev.org/download.php

SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/

// Excellent 2d physics library Box2D

http://box2d.org/about/

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

This topic is closed to new replies.

Advertisement