6 ms·
You could use smart pointers in c++11
by blackflame7000 8y ago
You could use smart pointers in c++11
- nurettin 8y agoYou could easily get a deadlock if a shared pointer gets destroyed within a thread it manages. Shared pointers alone are not the answer to memory safety.
- blackflame7000 8y agoI Said SMART not SHARED. That includes weak_ptrs and unique_ptrs
- nurettin 8y agoNot sure how that makes the situation any different.
- blackflame7000 8y agoShared_pointers are thread-safe from a creation and deletion aspect. Futhermore, you can use weak_ptrs to reference a shared_ptr and use that where you suspect a pointer might be deleted to a resource that is still required. Furthermore, the trusty old keyword const can make the pointer immutable thereby mitigating the problem. (And don't say what about const_cast.. because that's undefined behavior masquerading as acceptable because it rarely causes side-effects.
- nurettin 8y agoMy point is, "making sure x happens" or "follow this sure to work design philosophy which will break once the system is more complex than a game of billards" is not a guarantee to anything, therefore none of the smart pointers solve any problems about deadlocks caused by resource sharing.
- blackflame7000 8y agoI can tell you're not familiar with the latest C++ developments. RAII solves deadlocks so do things like std::lock_guard. C++ 11 is as safe as you're ever going to get while still maintaining fine granularity over the control of the system. C++ applications are some of the most vastly complicated programs in existence so I don't follow the argument that they break on projects larger than a breadbox.
- nurettin 8y agoI am familiar with all developments in C++ since 2001, that is why I am pretty sure that moving mutex primitives from platform level to language and memory model level has not changed anything in terms of deadlocks and you are just googling new stuff as we go.
- blackflame7000 8y agoYou should really check out the new stuff. It's a barely even the same language anymore. They've made many improvements.
- isaachier 8y agoThat isn't exactly a memory issue to be fair. It is deadlock.
- Jweb_Guru 8y agoSmart pointers guaranteeing memory safety is a meme that needs to die. If you exclusively use smart pointers and never use references, maybe it's true, but this precludes you from even using std::vector.