Check for null in std::shared_ptr

You have to consider that std::shared_ptr is overall still a pointer (encapsulated in a pointer like class) and that it can indeed be constructed to internally be nullptr. When that happens, expressions like: ptr-> *ptr leads to undefined behavior. So, yeah, if you are expecting the pointer to also be nullptr, then you should check … Read more

Should I use shared_ptr or unique_ptr

I’ve been making some objects using the pimpl idiom, but I’m not sure whether to used shared_ptr or unique_ptr. Definitely unique_ptr or scoped_ptr. Pimpl is not a pattern, but an idiom, which deals with compile-time dependency and binary compatibility. It should not affect the semantics of the objects, especially with regard to its copying behavior. … Read more

NULL pointer with boost::shared_ptr?

Your suggestion (calling the shared_ptr<T> constructor with no argument) is correct. (Calling the constructor with the value 0 is equivalent.) I don’t think that this would be any slower than calling vec.push_back() with a pre-existing shared_ptr<T>, since construction is required in both cases (either direct construction or copy-construction). But if you want “nicer” syntax, you … Read more

Is make_shared really more efficient than new?

As infrastructure I was using llvm/clang 3.0 along with the llvm std c++ library within XCode4. Well that appears to be your problem. The C++11 standard states the following requirements for make_shared<T> (and allocate_shared<T>), in section 20.7.2.2.6: Requires: The expression ::new (pv) T(std::forward(args)…), where pv has type void* and points to storage suitable to hold … Read more

std::shared_ptr thread safety

What you’re reading isn’t meaning what you think it means. First of all, try the msdn page for shared_ptr itself. Scroll down into the “Remarks” section and you’ll get to the meat of the issue. Basically, a shared_ptr<> points to a “control block” which is how it keeps track of how many shared_ptr<> objects are … Read more

std::shared_ptr: reset() vs. assignment

When using reset() the parameter passed to reset need not be a managed object (nor can it be); whereas with = the right hand side must be a managed object. So these two lines give you the same end result: p = std::make_shared<int>(5); // assign to a newly created shared pointer p.reset(new int(5)); // take … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)