Home » Developing U++ » U++ Developers corner » Core chat... (reference counted pointers etc.)
Re: Core chat... [message #12367 is a reply to message #12363] |
Fri, 26 October 2007 14:01   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
mdelfede wrote on Fri, 26 October 2007 07:03 |
luzr wrote on Fri, 26 October 2007 12:42 |
Sorry. My mistake. Forget about [10]. Only
ctrls.Create<Button>();
or (to be more clear):
Array<Ctrl> a, b;
a.Create<Label>();
a.Create<EditField>();
b = a;
b.Create<Label>(); // Now what?!
|
Array<Ctrl> a, b; // two empty arrays, reference to nothing
a.Create<Label>(); // adds a Label to a, a becomes an array with a single reference at underlying data
a.Create<EditField>(); // adds an EditField to a, a is grown by 1 element, as it had a single reference to data, nothing strange happens.
b = a; // now a AND b have both reference to the same underlying array
b.Create<Label>(); // underlying data is copied ....
|
How is it copied? There is no copy operation for widgets. And it does not even have sense.
Quote: |
[/code]
I see your point, here you *did* want a single array of controls, and you *did* want to destroy a when copying to b. You could have easily write :
Array<Ctrl> a;
a.Create<Label>();
a.Create<EditField>();
Array<Ctrl>&b = a;
b.Create<Label>();
That leaves both a and b pointing to SAME array.
|
Of course, but that is completely different thing.
In fact, yes, one of reasons to give away with reference counting for containers (or other "smart" approaches) is that you only seldem need to transfer the value of container at all.
OTOH, if you DO need such operation, then in most cases you either need exactly "pick" behaviour or you just do not care (function return value). Very seldom you need "deep copy" - in that case, you still have optional deep operations available.
And yes, sometimes you get "broken pick semantics" runtime assert. But I get 100 times more "invalid index" asserts than this one.
Quote: |
You then could say that when a is destroyed, b points to nothing, that's true, but I can hardly imagine such a case. For example :
Array<Ctrl> MyFunc()
{
Array<Ctrl> a;
a.Create<Label>();
a.Create<EditField>();
Array<Ctrl>&b = a;
b.Create<Label>();
return b;
}
Array<Ctrl> c = MyFunc();
still works...
|
But does not compile Your template needs deep public copy constructor for T, even if it is not actually used (because reference count is always 1 for COW ops).
Quote: |
and I can tell you that if you forget the & you have double controls on screen!
|
Sounds like a possible solution, but in that case you need to solve the quite complex problem of polymorphic copy - and all that only to make flawed code working somehow.
Mirek
[Updated on: Fri, 26 October 2007 14:02] Report message to a moderator
|
|
|
 |
|
Core chat... (reference counted pointers etc.)
By: mirek on Tue, 23 October 2007 23:48
|
 |
|
Re: Core chat...
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 16:37
|
 |
|
Re: Core chat...
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 17:46
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 18:23
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 20:24
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 22:05
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 23:36
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 05:33
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 14:06
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 14:34
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 15:19
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 18:02
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 19:52
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 21:33
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 23:26
|
 |
|
Re: Core chat...
By: mirek on Thu, 25 October 2007 23:38
|
 |
|
Re: Core chat...
By: mdelfede on Thu, 25 October 2007 23:47
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 09:36
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 12:13
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 12:42
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 13:03
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 14:01
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 14:18
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 22:09
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 23:13
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 23:51
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 18:47
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 22:12
|
 |
|
Re: Core chat...
By: mdelfede on Fri, 26 October 2007 23:09
|
 |
|
Re: Core chat...
By: mirek on Fri, 26 October 2007 23:55
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 11:08
|
 |
|
Re: Core chat...
By: mirek on Sat, 27 October 2007 11:16
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 13:06
|
 |
|
Re: Core chat...
By: mirek on Sat, 27 October 2007 14:50
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 15:21
|
 |
|
Re: Core chat...
By: mirek on Sat, 27 October 2007 16:02
|
 |
|
Re: Core chat...
By: mdelfede on Sat, 27 October 2007 16:28
|
 |
|
Re: Core chat...
By: sergei on Wed, 24 October 2007 19:49
|
 |
|
Re: Core chat...
By: mdelfede on Wed, 24 October 2007 20:06
|
 |
|
Re: Core chat...
By: mirek on Wed, 24 October 2007 21:46
|
Goto Forum:
Current Time: Sat May 10 04:43:08 CEST 2025
Total time taken to generate the page: 0.00972 seconds
|