reference-counting Questions
3
Solved
I'm looking for something roughly like this take, but atomic:
impl<T: Clone> for Arc<T> {
fn take(mut self) -> T {
Arc::make_mut(&mut self);
Arc::try_unwrap(self).unwrap()
}...
Ponderable asked 18/4, 2019 at 16:55
1
i'd like to gain understanding why following seems to not work properly in Rust.
I'd like to chunk a vector and give every thread a chunk to work on it. I tried it with a Arc and a Mutex combinati...
Gorizia asked 2/4, 2020 at 15:10
1
Solved
std::rc::Weak<T> has the following definition:
pub struct Weak<T: ?Sized> {
ptr: NonNull<RcBox<T>>,
}
In my understanding, when there's no more Rc<T> left, RcBox<...
Barrens asked 5/5, 2023 at 3:48
2
To write a ref-counted class, I have seen 2 different approaches:
Approach 1:
struct RefCounting1 {
void ref_up() {
m_ref.fetch_add(1, std::memory_order_relaxed);
}
void release() {
if (m_ref...
Headman asked 27/2, 2023 at 20:46
13
Solved
shared_ptr is a reference counting smart pointer in the Boost library.
The problem with reference counting is that it cannot dispose of cycles. I am wondering how one would go about solving this in...
Normalie asked 22/4, 2009 at 7:33
13
When using reference counting, what are possible solutions/techniques to deal with circular references?
The most well-known solution is using weak references, however many articles about the subje...
Pagepageant asked 1/7, 2009 at 14:11
6
Solved
I need a base class like TInterfacedObject but without reference counting (so a kind of TNonRefCountedInterfacedObject).
This actually is the nth time I need such a class and somehow I always end...
Yang asked 16/8, 2011 at 14:50
2
Rust can handle reference counting very elegantly with Rc. It seems many members of the community prefer not to use this and instead use the ownership/borrowing semantics of the language. This resu...
Leavening asked 26/9, 2021 at 19:25
1
Solved
I am reading C++ concurrency in action 2nd.
It introduces split reference counts for a lock free stack.
One possible technique involves the use of not one but two reference counts for each node: a...
Unwitting asked 3/5, 2021 at 14:51
2
Solved
I have the following code which uses both Rc and Box; what is the difference between those? Which one is better?
use std::rc::Rc;
fn main() {
let a = Box::new(1);
let a1 = &a;
let a2 = &...
Andre asked 20/3, 2018 at 5:59
1
Solved
I'm trying to understand the pros and cons between:
using Arc and cloning the Arc (I'm using Something in various places/threads)
vs
using Something.clone() (my Something struct only ha...
Senatorial asked 10/6, 2020 at 10:44
3
Solved
Here's an example:
use std::rc::Rc;
#[derive(PartialEq, Eq)]
struct MyId;
pub fn main() {
let rc_a_0 = Rc::new(MyId);
let rc_a_1 = rc_a_0.clone();
let rc_b_0 = Rc::new(MyId);
let rc_b_1 = rc...
Rosanne asked 8/6, 2016 at 15:18
1
Solved
I am reading the Rust Book and everything was pretty simple to understand (thanks to the book's authors), until the section about lifetimes. I spent all day, reading a lot of articles on lifetimes ...
Hardshell asked 9/11, 2019 at 19:48
4
Solved
Quoted from C++ Primer $12.1.6:
A weak_ptr (Table 12.5) is a smart pointer that does not control the lifetime of the
object to which it points. Instead, a weak_ptr points to an object that is ...
Lustral asked 31/3, 2018 at 8:28
0
The situation: My code uses a reference-counting pointer class (similar in spirit to boost::intrusive_ptr) to manage its dynamic allocations and avoid memory leaks.
AFAICT this works fine and does...
Permalloy asked 12/1, 2019 at 20:26
1
Solved
How does Rust handle the "island of isolation" scenario for Rcs and Arcs?
An "island of isolation" is a situation where object A contains a pointer to object B and object B contains a pointer to o...
Evvoia asked 28/12, 2018 at 17:15
2
Solved
I'm writing a simple chat server which broadcasts messages to all the clients connected.
The code might look terrible, since I'm a beginner. Peers are not used anywhere yet, since I want to pass ...
Ramirez asked 9/12, 2018 at 11:7
1
Solved
The following code gets some variables in closures and returns a struct containing that data.
I can't return the struct with that data even when I box the struct and clone the variables; they are ...
Beatriz asked 2/12, 2018 at 23:51
2
Solved
I have a question, please go through the following simple C++ program,
int main( )
{
shared_ptr<int> sptr1( new int );
shared_ptr<int> sptr2 = sptr1;
shared_ptr<int> sptr3;
s...
Elementary asked 22/10, 2018 at 9:35
4
Solved
I'm trying to make a type system while using QSharedData. The idea is simple, there will be a number of different data types, each of which is going to be derived from the base abstract class. I wa...
Dive asked 25/9, 2012 at 8:34
1
Solved
This performance optimization WWDC video suggests that strings are reference counted because they are on the heap. This has implications on the performance of structs with Strings and whether somet...
Serf asked 15/9, 2017 at 21:8
2
Given this class which is enable_shared_from_this:
class connection : public std::enable_shared_from_this<connection>
{
//...
};
Suppose I create two instances of std::shared_ptr from the...
Herren asked 13/11, 2017 at 4:46
1
Solved
Let's say I have a shared_ptr to an array:
std::shared_ptr<int> sp(new T[10], [](T *p) { delete[] p; });
And a method:
shared_ptr<T> ptr_at_offset(int offset) {
// I want to return...
Swindell asked 27/9, 2017 at 17:9
6
Solved
Reference cycles in Swift occur when properties of reference types have strong ownership of each other (or with closures).
Is there, however, a possibility of having reference cycles with value t...
Nonstriated asked 4/7, 2016 at 19:46
0
When I do a retain count on this object it is 2. Why is this? Surely it should be one as I have just initialised it and not assigned it or anything...
let testC: TestClass = TestClass()
print(CFGe...
Clerc asked 19/12, 2016 at 10:18
1 Next >
© 2022 - 2024 — McMap. All rights reserved.