ownership-semantics Questions

4

Solved

I have the following sketch of an implementation: trait Listener { fn some_action(&mut self); fn commit(self); } struct FooListener {} impl Listener for FooListener { fn some_action(&m...
Menorca asked 7/10, 2017 at 13:35

3

Solved

I know that std::unique_ptr is used when an object has only one owner and std::shared_ptr is used when an object has multiple owners. What does it mean to be the unique owner of an object? Does be...
Overlap asked 11/11, 2019 at 14:32

1

Solved

fn func(s: *mut String, a: *mut i32) -> usize { println!("{}", unsafe { *s }); println!("{}", unsafe { *a }); unsafe { (*s).len() } } fn main() { let mut s = String::from("hello"); let mu...
Humbertohumble asked 19/12, 2017 at 4:2

1

Solved

I want to write a generic function that accepts any kind of string (&str/String) for convenience of the caller. The function internally needs a String, so I'd also like to avoid needless re-a...
Underpin asked 6/8, 2017 at 19:30

3

Solved

I have some non-copyable type and a function that consumes and (maybe) produces it: type Foo = Vec<u8>; fn quux(_: Foo) -> Option<Foo> { Some(Vec::new()) } Now consider a type t...
Nameplate asked 15/7, 2016 at 13:17

5

Solved

Say there is an object A which owns an object B via std::unique_ptr<B>. Further B holds a raw pointer(weak) reference to A. Then the destructor of A will invoke the destructor of B, since it ...
Splendor asked 22/6, 2016 at 6:22

3

Solved

I'm currently trying to write a little command line app in Rust and I've hit a wall with lifetimes. extern crate clap; use self::clap::{App, Arg}; use std::env; impl<'p> Params<'p> { ...
Barthelemy asked 28/5, 2016 at 18:42

1

Solved

There is a great example of Rust's move semantics documented here: Rust Move Semantics on the Rust By Example website. I have a basic understanding of both cases demonstrated. The first being how ...
Hussite asked 26/3, 2016 at 1:46

1

Solved

There is a vector resource that is allocated in line 2 of the program below. When the program ends, the vector resource is not owned. If a resource is not owned at all, when does it get reclaimed? ...
Hetzel asked 12/8, 2015 at 2:39

2

Perhaps I was trying to be too generic. (Original question below) Concretely, I have some dependency Dep of a class Foo. I also have a class MockDep and am defining a class TestFoo. Here is its con...
Lashanda asked 9/6, 2014 at 23:3

3

Solved

I'm primarily a C++ programmer, and I've grown used to having class templates like std::unique_ptr, std::shared_ptr, etc for expressing ownership of my objects. Does Delphi have anything that is si...
Mukul asked 12/9, 2013 at 12:43

2

Solved

Handles have proper semantics other than pointers. So for me an example like this (extracted from the Rule of Zero): class module { public: explicit module(std::wstring const& name) : handle ...
Sphacelus asked 14/2, 2013 at 15:22

3

Solved

I've written a static factory method that returns a new Foobar object populated from another data object. I've recently been obsessed with ownership semantics and am wondering if I'm conveying the ...
Phraseology asked 3/1, 2012 at 21:51

12

Solved

I'd like the destructor of my class to delete the entire object except for one of the members, which is deleted elsewhere. First of all, is this totally unreasonable? Assuming it's not, how do I do...
Lona asked 6/7, 2009 at 17:30

11

Solved

C++ is all about memory ownership - aka ownership semantics. It is the responsibility of the owner of a chunk of dynamically allocated memory to release that memory. So the question really be...
Retouch asked 18/9, 2008 at 16:35
1

© 2022 - 2024 — McMap. All rights reserved.