Ownership semantics are a set of rules that govern the lifetime of allocated resources. Ownership semantics determine when and how allocated resources can be freed, and whether ownership can be shared.
Questions tagged [ownership-semantics]
67 questions
0
votes
2 answers
What is the scope of the returned value in Rust?
What happens to the data referenced by the variable when it is returned to the caller? When the data is destroyed and possibly Drop trait gets executed?
user625070
0
votes
3 answers
Ownership of my new Unique_ptrs?
As per suggestion at a job interview I had recently, I was advised to research into the unique_ptr functionality of C++11, as a means of automated garbage collection. So I'm using an older project and replacing my raw pointers to objects created…

Guy Joel McLean
- 1,019
- 4
- 12
- 34
-1
votes
1 answer
Conditionally passing ownership for members
Assume the following sketch:
struct C {
(either T or T&) m_t;
C(T& t):
(instantiate m_t as T& m_t(t))
{}
C(T&& t):
(instantiate m_t as T(t))
{}
};
such that a C either has or has not ownership of t, depending on…

Bubaya
- 615
- 3
- 13
-1
votes
2 answers
Extending/Incrementing the ref count of a smart pointer
Suppose I have a method that defines a shared_ptr. After the method finishes, the shared_ptr will also be deleted. In the interim I have another member that uses that shared_ptr. So I would like to extend the lifetime of the shared_ptr past the…
user3091673
-1
votes
1 answer
Why does Rust require ownership annotations instead of inferring it?
How come Rust does not fully infer ownership of its variables? Why are annotations needed?

Olle Härstedt
- 3,799
- 1
- 24
- 57
-2
votes
1 answer
How to safely store a reference to owner in an owned C++ object?
Class Owner owns multiple objects of class Item via unique_ptr. I want objects of Item to store a reference (not a pointer) to the Owner objects which owns them, with the following requirements:
There can never be a dangling reference.
The…

quant_dev
- 6,181
- 1
- 34
- 57
-2
votes
2 answers
C++ shared pointers of parent-children classes
I have a scenario in which I need to collect all the objects of a type in a collection, but I also need a collection of some of its inherited types. Example:
class Particle: public someClass
{
...
public:
static…

Adam Hunyadi
- 1,890
- 16
- 32