Author Archives: astar

An example when we don’t need std::shared_ptr in C++

In the previous example, independent components needed shared ownership of cached objects. For a TCP session, however, we can compare two designs: multiple callbacks keeping the session alive through std::shared_ptr, or a single owning coroutine using std::unique_ptr and structured concurrency. In the second design, reading and writing still run concurrently, but the owner waits for both operations to stop before destroying the session. No shared ownership or reference counting is needed.

(more…)