Talk:Smart pointer
From Wikipedia, the free encyclopedia
Archives |
moved to Handle (computing) |
[edit] Example
I have included an example in C++ language. Note I was aware of WP:MOS#Avoid_first-person_pronouns_and_one. I thought first person was suitable because the comments behave as a mathematical deduction.
I have tried to make the example independent from whether the approach is intrusive, so it does not depend on the counter being stored into the object, as well as it does not depend on the counter being stored into the smart pointer. For instance, q = obj_1; instead of q = p; will not work in the latter case.
Also, the following will not work with some implementations (as stated by Alexandrescu, Modern C++ Design) so I modified the example for compatibility with the general case.
Object* obj_1 = new Object(); SmartPointer<Object> p= obj_1; SmartPointer<Object> q= obj_1;
Rjgodoy 16:12, 29 May 2007 (UTC)
I would like your opinion about this paper (in Spanish). It contains an analysis of drawbacks which could be useful in the article (sections 3 and 4). However, since I'm one of the authors of that work, I submit it for discussion, per WP:COI. Rjgodoy 23:25, 29 May 2007 (UTC)
[edit] track of the objects that point to them/they point
The wording "[SPs] keep track of the objects that point to them" instead of "[SPs] track of the objects that they point" is intentional. A SP tracks how many objects are actually pointing *it* (because the raw pointer cannot track them by itself) and each SP usually manages only one object. Besides of some quirks, it seems as if the outer objects were pointing to the target object, but they are pointing to the SP. I hope the distinction is clear.
Rjgodoy (talk) 11:37, 14 May 2008 (UTC)
- Jagat sastry wrote: "But isn't the smart pointer supposed to point to the object whatsoever?"
-
- In short, the answer to your question is yes, they point to the target object, but they track how many references (to the smart pointer, and indirectly to the target object) are in scope at any given moment. The target object itself is not tracked but managed. Rjgodoy (talk) 02:59, 15 May 2008 (UTC)
Well, yeah. That does make sense. Nice word Rjgodoy!
Jagat sastry (talk) 07:50, 15 May 2008 (UTC)