Top "Smart-pointers" questions

An abstract data type that simulates a pointer while providing additional features, such as automatic garbage collection or bounds checking

c++ shared_ptr of stack object

I have been learning managed pointers lately and ran into the following scenario. I am implementing a model/controller class …

c++ heap-memory smart-pointers stack-memory
RAII vs. Garbage Collector

I recently watched a great talk by Herb Sutter about "Leak Free C++..." at CppCon 2016 where he talked about using …

c++ memory-leaks garbage-collection smart-pointers
Shared void pointers. Why does this work?

To solve a very peculiar problem in my application I need a shared-pointer to allocated data, but to the outside …

c++ visual-c++ c++11 shared-ptr smart-pointers
unique_ptr heap and stack allocation

Raw pointers can point to objects allocated on the stack or on the heap. Heap allocation example: // heap allocation int* …

c++11 pointers smart-pointers heap-memory unique-ptr
Is there a non-atomic equivalent of std::shared_ptr? And why isn't there one in <memory>?

This is a bit of a two part question, all about the atomicity of std::shared_ptr: 1. As far as …

c++ c++11 smart-pointers
does make_unique value initializes char array

For example - #include <memory> int main(){ const auto bufSize = 1024; auto buffer = std::make_unique<char[]>(…

c++ c++11 memory c++14 smart-pointers
Use of observer_ptr

What exactly is the point of the construct std::observer_ptr in the library fundamentals technical specification V2? It seems …

c++ smart-pointers c++17
C++11 Smart Pointer Semantics

I've been working with pointers for a few years now, but I only very recently decided to transition over to …

c++ pointers c++11 smart-pointers
enable_shared_from_this - empty internal weak pointer?

I'm using enable_shared_from_this<Base> and then inherit from Base. When trying to use shared_from_…

c++ boost c++11 shared-ptr smart-pointers
Unique pointer and const correctness

I was not expecting this code to compile: #include <iostream> #include <memory> class A { public: inline …

c++ pointers smart-pointers const-correctness object-composition