Skip to main content
-3 votes
1 answer
132 views

I am trying to create Linkedlist, where array is passed, and linkedlist is returned. However, there seems something wrong, and the linkedlist returned is circular. /** * Shared pointer, pass vector ...
Susobhan Das's user avatar
  • 1,310
-5 votes
3 answers
209 views

Consider passing a shared pointer of const std::shared_ptr<Object> to the ctor of following class. struct MyClass { explicit MyCLass(const std::shared_ptr<const Object> & input) : ...
Alex Suo's user avatar
  • 3,167
2 votes
1 answer
197 views

Context We store triangular mesh data in large buffers as Buffer = std::vector<char>. These buffers can easily reach 1 GB in size. We also share these buffers as SharedBuffer = std::shared_ptr&...
stgatilov's user avatar
  • 5,673
0 votes
1 answer
182 views

How does the implementation of C++ std::weak_ptr upgrade to std::shared_ptr and access the object without risking a use-after-free? The scenario: In a concurrent setting, you have a weak pointer to an ...
Qwert Yuiop's user avatar
4 votes
1 answer
134 views

TL;DR How can a std::shared_ptr be created from an expired std::weak_ptr so that it uses the same control block as the std::weak_ptr? I ran the following test case, and noticed two oddities: #include ...
leekillough's user avatar
  • 1,117
2 votes
1 answer
81 views

I am using a holder class to store a std::shared_ptr to another C++ class created in Python thus: #include <memory> #include <iostream> #include <pybind11/pybind11.h> class Child { ...
Olly's user avatar
  • 86
5 votes
0 answers
250 views

In this earlier SO question: What is a smart pointer and when should I use one? Ten years ago, I gave a relative simple answer and got a bunch of upvotes. One paragraph in my answer reads: Use std::...
einpoklum's user avatar
  • 137k
-1 votes
3 answers
183 views

Just experimenting with shared_ptr to explore its functionalities. I'm constructing a new shared_ptr object using a raw pointer from other shared_ptr object. The following code is compiling and runs ...
Artur Brodsky's user avatar
0 votes
3 answers
180 views

I have a following issue in C++. I am creating an object factory, which has a method returning shared_ptr to an object of class. The object factory uses a buffer of pre-allocated objects called "...
majvan's user avatar
  • 59
1 vote
4 answers
141 views

If a shared_ptr is declared twice managing the same object, why does the count not increase to two, since the same object is being managed? int i = 1; std::shared_ptr<int> p1 = std::...
random_acct's user avatar
1 vote
1 answer
144 views

In "C++ Concurrency in action" from Anthony Williams (2012) there is a thread safe queue implemented by storing std::shared_ptr<T> like so template<typename T> class ...
Niccolò Tiezzi's user avatar
3 votes
0 answers
134 views

I have many threads which share access to the same pool of objects, and some threads could remove objects, so I use std::vector<std::shared_ptr<T>> to hold pointers to the objects so that ...
Damir Tenishev's user avatar
10 votes
5 answers
686 views

I want to apply the same template algorithm to std::vectors which contain objects of some type T and (different) std::vectors which contain std::shared_ptrs to objects of some type T. Can I ...
Damir Tenishev's user avatar
-3 votes
2 answers
168 views

I am developing a game in C++, and have been using vectors of smart pointers to store some level data. The game runs and works without issue, but I was wondering whether or not the memory held by the ...
Fishie's user avatar
  • 37
8 votes
0 answers
203 views

Prior to C++20 a std::shared_ptr<T> could be accessed without synchronization via its methods, or atomically using std::atomic_... functions. In C++20, these functions are deprecated, and ...
Fedor's user avatar
  • 24.7k

15 30 50 per page
1
2 3 4 5
227