For questions about the usage of the smart pointer construct.
3
votes
1answer
133 views
Unique pointer initialisation
What is the correct initialisation of a smart pointer?
std::unique_ptr<Class> ptr(std::make_unique<Class>());
or
std::unique_ptr<Class> ptr = std::make_unique<Class>();
...
5
votes
2answers
190 views
Factories, vectors and smart pointers - Design Question
So, my Business Code needs some Objects.
It does not know how much objects it needs and it does not know the exact types (because polymorphism is involved).
For me, that sounds for a good reason to go ...
1
vote
1answer
145 views
State Machine Memory Management Problems
My state machine handles requests and returns the next state. In the below simplification, I've got two states here, CreatedState and RunningState. Running state is the end state, and just returns ...
12
votes
5answers
816 views
C++: Should class own or observe its dependencies?
Say I have a class Foobar that uses (depends on) class Widget. In good ol' days, Widget wolud be declared as a field in Foobar, or maybe as a smart pointer if polymorphic behavior was needed, and it ...
3
votes
3answers
358 views
Possible alternatives to copy constructors
In my C++ project I am relying on some libraries that do memory management for me. I make wrapper classes, for ease of use and memory safety, for example the class below. Note that this is a much ...
7
votes
1answer
481 views
Key / Value store development porting to modern C++
I am developing a database server similar to Cassandra.
Development were started in C, but things became very complicated without classes.
Currently I ported everything in C++11, but I am still ...
3
votes
2answers
192 views
C++ using shared_ptr with API [closed]
I'm building a library that generates a couple of types of objects that can be used by user code and the library. To keep track of these objects, I'd like to use shared_ptr's, so I can build in some ...
7
votes
1answer
5k views
raw, weak_ptr, unique_ptr, shared_ptr etc… how to choose them wisely
There is a lot of pointers in C++ but to be honest in 5 years or so in c++ programmation (specifically with the Qt Framework) I only use the old raw pointer :
SomeKindOfObject *someKindOfObject = ...
3
votes
3answers
448 views
Polymorphic template container: shared_ptr vs reference_wrapper
Assuming we have two classes:
class A
{
...
}
class B : public A
{
...
}
Would it be better to write
std::deque<shared_ptr<A> > container;
or
...
1
vote
1answer
1k views
C++ Templates where the type is a shared_ptr
When creating template classes in C++, if the type upon which the template will be specialized is intended to be a shared_ptr type, is it better to make T a shared_ptr type or make T a non-pointer ...
9
votes
3answers
243 views
Will destructing a large list overflow my stack?
Consider the following singly linked list implementation:
struct node {
std::unique_ptr<node> next;
ComplicatedDestructorClass data;
}
Now, suppose I stop using some ...
0
votes
3answers
1k views
C++ Chess board design and smart pointers [closed]
I wrote a Chess engine in Java and I am porting it over to C++. I am new to C++.
The idea:
I have a Board object which holds a 2-dimensionnal array of Piece objects. Queen, Rook, Bishop, etc are ...
0
votes
1answer
63 views
confusion regarding handling of new smart pointers on stack frames?
Let me try to elaborate it.
Stack Frame: When we execute any function it create stack where all local variables and instructions reside.
And Smart Pointer: smart pointer like std::unique_ptr allows ...
23
votes
5answers
4k views
Why can't Java/C# implement RAII?
Question:
Why can't Java/C# implement RAII?
Clarification:
I am aware the garbage collector is not deterministic. So with the current language features it is not possible for an object's Dispose() ...
2
votes
2answers
289 views
How do I get rid of cyclic references in this design?
I have 3 classes: Meeting, Project and Agenda.
A Project contains all sort of information + a list of meetings.
The Agenda contains a list of upcoming Meetings.
A Meeting contains some data + a list ...
2
votes
1answer
420 views
gtkmm manage/add vs smart pointers:
gtkmm provides lifetime management of widgets using
Gtk::Widget* aWidget = Gtk::manage(new Widget());
Gtk::Widget.add(*aWidget);
This delegates lifetime management of aWidget to its container ...
9
votes
4answers
558 views
Is Non-Deterministic Resource-Management a Leaky Abstraction?
From what I can see, there are two pervasive forms of resource-management: deterministic destruction and explicit. Examples of the former would be C++ destructors and smart pointers or Perl's DESTROY ...
4
votes
2answers
2k views
Smart Pointers inside class vs Normal Pointers with Destructor
Regarding pointers which are members of classes. Should they be of a smart pointer type or is it enough to simply deal with them in the destructor of the class they are contained in?
42
votes
10answers
10k views
Why Garbage Collection if smart pointers are there
These days, so many languages are garbage collected. It is even available for C++ by third parties. But C++ has RAII and smart pointers. So what's the point of using garbage collection? Is it doing ...