Skip to main content
Filter by
Sorted by
Tagged with
1 vote
3 answers
123 views

There's a whole page on the Tcl wiki, but there are a lot of examples and it's hard for me to find them. Here are two simple cases that I often use: Tcl_Obj *innerObj = NULL; innerObj = Tcl_NewListObj(...
Mkn's user avatar
  • 668
0 votes
1 answer
103 views

I have a Scene struct holding resources for the program and Objects referencing resources of the scene and also being owned by the scene. So the resources are wrapped in Rc<>. Rust playground ...
Nonoreve's user avatar
  • 137
0 votes
0 answers
20 views

In OpenCL (let's say v3.0), I know one can create contexts using sub-devices. But - what happens if you release all references to a sub-device while the context is not released (i.e. has positive ...
einpoklum's user avatar
  • 138k
0 votes
1 answer
61 views

In this pycon conference the presenter says that ctypes.c_long.from_address(id(SOME_OBJECT)).value would yields the reference count of an object. I tried to find this in the documentation but found ...
Amir reza Riahi's user avatar
0 votes
1 answer
140 views

Is this code safe knowing that: Header_mark_as_shared is always only called before an object crosses to other threads, no matter in which thread it resides in The first call to Header_mark_as_shared ...
João Pires's user avatar
  • 1,017
3 votes
2 answers
244 views

Giving the following constraints, is the optimization in this code correct? before an object is transfered to another thread, its reference count is incremented and is_shared is set to true. ...
João Pires's user avatar
  • 1,017
0 votes
0 answers
44 views

I am still a bit newer to rust and have been getting some practice through Advent of code problems. I am curious if anyone would be able to explain to my why the borrow checker is dislikes the ...
Justin Landis's user avatar
2 votes
1 answer
86 views

I was experimenting with refcount of objects, and I noticed the reference count of None object does not change when I bind identifiers to None. I observed this behavior in python version 3.13. Python ...
Amir reza Riahi's user avatar
1 vote
1 answer
121 views

There is probably no way this is the first time someone has asked this question, but for the life of me I couldn't find this answer. So I want to ask this in the hope that someone will either harshly ...
Alaska's user avatar
  • 423
2 votes
1 answer
102 views

IncRef: refcount.fetch_add(1, std::memory_order_relaxed) DecRef: if (refcount.load(std::memory_order_relaxed) == 1 || refcount.fetch_sub(1, std::memory_order_release) == 1) { std::...
Luddes's user avatar
  • 21
0 votes
0 answers
52 views

a bit related to In Objective-C MRR, if foo is a retain property, then self.foo = [[Foo alloc] init] will need to be released immediately? suppose you have @property (nonatomic, readwrite, retain) ...
Anton Tropashko's user avatar
0 votes
1 answer
94 views

get_user_pages() increments the page reference count. And that is why it can pin the page in memory. So I wonder whether the pages obtained by get_user_pages() can be directly recycled or swapped out ...
Mia8Cew's user avatar
0 votes
2 answers
126 views

I'm writing a bit of code that uses Rc<String>. I'm pretty sure that using this would create an extra pointer indirection, with one pointer to the Rc, which has a pointer to String, which is a ...
ora's user avatar
  • 1
6 votes
0 answers
136 views

I was reading the Python 3.12 official documentation on the sys module, and the part about getrefcount() seems rather confusing to me (emphasis mine). Return the reference count of the object. The ...
Weijun Zhou's user avatar
  • 5,568
0 votes
0 answers
51 views

To improve my understanding of Cython, I am trying to find a way to directly access the fields of the objects defined by CPython. For example, I wrote the following code to access the ob_item field of ...
Sylvain Leroux's user avatar
1 vote
2 answers
304 views

I have a struct Region which contains [Option<Rc<RefCell<Region>>>; 2] as its subregions and Option<Weak<RefCell<Region>>> as its container. I am writing a method ...
user21749640's user avatar
2 votes
1 answer
73 views

I am running into a strange issue using pytest and mock: I am trying to create a call to __del__ by deleting an object using del .... According to the documentation, del only reduces the reference ...
Markus A.'s user avatar
  • 12.9k
1 vote
1 answer
105 views

I am an absolute beginner with rust, so apologies if my question is not phrased in the correct terms, I am happy to provide more clarification if needed. I am writing a program using sdl and rlua. ...
HvyWpnDd's user avatar
0 votes
2 answers
88 views

In this part of the talk on GIL by Larry Hastings, there is an explanation about how ironclad provides C-extension compatibility with IronPython. This is the interesting part of the talk: We ...
Saleh's user avatar
  • 1,962
1 vote
1 answer
103 views

I have a trait for objects that can provide bytes from some index. These could be files, processes being ptraced, caches over other byte providers, etc.: use std::result::Result; use std::io::Error; ...
Robert Larsen's user avatar
0 votes
0 answers
91 views

Let's say I have allocated a string using SysAllocString. A separate class which is using the string calls SysAddRefString. Before it releases the string with SysReleaseString, the original owner ...
drgs's user avatar
  • 408
0 votes
1 answer
69 views

I am currently reading More Effective C++ (1995) by Scott Meyers. In Item 29 - Reference Counting, the author metioned that the primary benefits of using reference counting are (1) "Simplify ...
The Lonesome Coder's user avatar
2 votes
0 answers
140 views

I am new to python and while I was counting the references to the number "3" in the context of embedding Python in C++ I found out a behavior that I was not expecting at all. Can someone ...
Guido Gagliardi's user avatar
0 votes
1 answer
126 views

I have difficulties understanding how to correctly count a reference variables. Example (adopted from some book for java learning): class Car { } class Example { public static void main(String[] ...
ImNotARobot's user avatar
4 votes
0 answers
156 views

Context I have a troublesome object from third-party code in a Python (3.10) program. The object is not written in pure Python; it's provided by an extension module. Due to a bug in the third party ...
Zac B's user avatar
  • 4,312
1 vote
0 answers
274 views

English is not my native language, so please excuse any typing errors. I am using a translator for my question. I learned from watching "WWDC16 - Understanding Swift Performance" that when ...
codingmon's user avatar
7 votes
1 answer
771 views

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<...
Calo's user avatar
  • 73
1 vote
2 answers
498 views

If a function creates a lot of objects in a loop that are not referenced elsewhere, they will be removed immediately due to Python's reference counting. If I store the objects in a list this time, the ...
Holzner's user avatar
  • 13
0 votes
2 answers
159 views

Result in Test is NOT always initially () I have found Do I need to setLength a dynamic array on initialization?, however I do not fully understand that answer More importantly, what is the best ...
hundreAd's user avatar
  • 158
2 votes
1 answer
264 views

Consider the following code: import sys a = [1, 2, 3] def foo(x): print(sys.getrefcount(x)) foo(a) # prints out 4 -- but why? When we invoke foo(a) and when print(sys.getrefcount(x)) executes, ...
lamc's user avatar
  • 367
5 votes
2 answers
205 views

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 (...
Afshin's user avatar
  • 9,240
0 votes
1 answer
48 views

I'm looking for a concurrency design pattern in C++ which enables a single resource instance to be constructed by the first thread which needs it, persist as long as at least one thread is accessing ...
NKatUT's user avatar
  • 519
-2 votes
1 answer
481 views

I have this function: use std::rc::Rc; fn rc_counter() -> Rc<String> { let p1 = Rc::new(String::from("Hello")); println!("count {}", Rc::strong_count(&p1)); //...
Yilmaz's user avatar
  • 51k
0 votes
1 answer
287 views

I've written some code to break up independent chunks of a computation into pieces and then feed each of the pieces to a thread pool which then does the computation and passes the result back the main ...
Hadi Khan's user avatar
  • 595
0 votes
0 answers
419 views

I want to implement the observer pattern using Weak smart pointers. Ideally this would look something like the following (playground): use std::cell::RefCell; use std::rc::{Rc, Weak}; struct ...
frankplow's user avatar
  • 522
1 vote
1 answer
163 views

I'd like to create a vector of TestStruct. TestStruct has an optional reference to another TestStruct instance. No TestStruct will ever reference itself, nor will there be circular references with the ...
Simplex's user avatar
  • 1,000
1 vote
1 answer
536 views

I know of these three techniques: Manually uses System.Classes; procedure DoSomething; var sl: TStringList; begin sl := TStringList.Create; try finally sl.Free; // Invoking destructor ...
complete_stranger's user avatar
0 votes
1 answer
413 views

Some implementations calls DllAddRef() and DllRelease() in the CClassFactory constructor, destructor, and LockeServer member function: https://github.com/microsoft/workbooks/blob/master/Clients/...
wmjdgla's user avatar
  • 602
0 votes
1 answer
76 views

I have this method: fn parse_http_request_headers<'b>(sp: &'b mut std::str::Split<&str>) -> HashMap<String, String> { let mut headers: HashMap<String, String>...
Alex Vergara's user avatar
  • 2,345
1 vote
1 answer
181 views

if we override malloc and new function we can track first created pointer . but how can i track and count other pointers and functions that using this allocated memory ? (q pointer in below code ) ...
esmaeil.zivari's user avatar
0 votes
1 answer
123 views

#include <stdio.h> #include <stdbool.h> #include <stdint.h> #include <glib.h> void transform_pointer_contents(GArray* const arr) { GArray* const tmp = g_array_new(true, ...
karobar's user avatar
  • 1,360
0 votes
1 answer
485 views

Looking at this implementation of std::shared_ptr https://thecandcppclub.com/deepeshmenon/chapter-10-shared-pointers-and-atomics-in-c-an-introduction/781/ : Question 1 : I can see that we're using std:...
not_that_guy123's user avatar
0 votes
1 answer
347 views

I have some points of clarification based on reading the internal implementations for zvals described here Internal value representation in PHP 7 - Part 1 and Internal value representation in PHP 7 - ...
user137364's user avatar
0 votes
1 answer
118 views

In a CPython multithreaded environment, consider the following code class Container: def __del__(self): # Some code that fails when run in a different thread than the thread that ...
Ozgur Akcali's user avatar
  • 5,522
2 votes
2 answers
290 views

https://en.cppreference.com/w/cpp/memory/shared_ptr/use_count states: In multithreaded environment, the value returned by use_count is approximate (typical implementations use a memory_order_relaxed ...
Chris Rajula's user avatar
4 votes
2 answers
244 views

I've defined two simple Python functions that take a single argument, raise an exception, and handle the raised exception. One function uses a variable to refer to the exception before raising/...
Andrew's user avatar
  • 2,922
2 votes
1 answer
2k views

Am I able to create an Rc with zero (strong) references? How to do this? I am doing references counting digraphs. An empty digraph would be represented as an Rc variable with zero references. If it is ...
porton's user avatar
  • 5,909
5 votes
2 answers
418 views

I'm wondering about code like this: def all_lines(filename): with open(filename) as infile: yield from infile The point of a context manager is to have explicit control over the lifetime ...
Homer512's user avatar
  • 15.1k
0 votes
2 answers
548 views

I am practicing deleting node in BST and came across the following code. def deleteNode(root, key): if root is None: return root if key < root.key: root.left = deleteNode(...
caden Hong's user avatar
2 votes
1 answer
120 views

Python works with reference counting. That means, if there is no more reference to a value, then the memory of that value is recycled. Or in other words. As long as there is at least one remaining ...
Hatatister's user avatar
  • 1,064

1
2 3 4 5
10