Home » Developing U++ » U++ Developers corner » Core chat... (reference counted pointers etc.)
Re: Core chat... [message #12395 is a reply to message #12392] |
Sat, 27 October 2007 15:21   |
mdelfede
Messages: 1308 Registered: September 2007
|
Ultimate Contributor |
|
|
I did ask the former question because I was lookin' inside MainWindow code.... Looking for the OpenGL bug.
But then I realized that Ctrl::Add() is quite different from Array::Add(), building an array of references instead of objects.
BTW, I still didn't find the bug there... The only thing I found (up to now) is shown in my code here :
int zzz;
MyAppWindow *win, *win2;
win = new MyAppWindow;
win2 = new MyAppWindow;
OpenGLExample gl, gl2;
gl.SetFrame(InsetFrame());
gl2.SetFrame(InsetFrame());
win->Add(gl.HSizePos(10, 10).VSizePos(10, 10));
win2->Add(gl2.HSizePos(10, 10).VSizePos(10, 10));
win->Sizeable().Zoomable();
win2->Sizeable().Zoomable();
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 0
win->OpenMain();
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 1
win2->OpenMain();
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 2
delete win;
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 2 !!!
delete win2;
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 2 !!!
Ctrl::EventLoop();
If I suppress the lines :
win->Add(gl.HSizePos(10, 10).VSizePos(10, 10));
win2->Add(gl2.HSizePos(10, 10).VSizePos(10, 10));
The code works ok :
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 0
win->OpenMain();
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 1
win2->OpenMain();
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 2
delete win;
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 1
delete win2;
zzz = Ctrl::GetTopCtrls().GetCount(); // zzz = 0
That works even if I leave both lines BUT OpenGLExample is *not* derived from GLControl.
I'd like to know if the bug is Linux-dependent or not... But I haven't an Ide setup on my win xp machine. Don't you have a bit time to test on windows ?
Back to refcounted objects. What about if Ctrl would be an object built with PIMPL idiom and refcounted ? You then could write :
aControl a; // control is created
aControl b = a; // just reference to inner pimpl object is copied
or, what sound even better:
Vector<Ctrl>*a, *b;
Ctrl c; // control is created, RefCount == 1
a = new Vector<Ctrl>;
b = new Vector<Ctrl>;
a->Add(c); // a gets a *copy* of c, but in reality it adds just to refcount of c, that becomes 2
b->Add(c); // b gets a *copy* of c, but in reality it adds just to refcount of c, that becomes 3
delete a; // a gets destroyed, RefCount in c becomes 2
The advantage of this instead of references of an object ? Well... you must not care of ownership.... and you can be sure object is freed on last reference lost.
As usual, that brings some performance lost.
Ciao
Max
|
|
|
 |
|
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: Wed Jun 25 10:06:36 CEST 2025
Total time taken to generate the page: 0.04319 seconds
|