> On 08/19/11 08:00, Chris wrote:
> > this->win->label("TEST");
>
> All quoted strings are static, so it survives
> the entire program's execution.
>
> Static strings are not allocated or freed the way
> dynamic memory is; static data is compiled into the
> executable, so it's there for as long as the executable
> runs.
>
The doubt is born during debugging of my program. Today i've
discovered the 'mistake'. I'm using copy_label for
Fl_Multiline_Output widget, and in that case the string is
actually copied some bytes after the widget pointer, in the
heap region. The fact is that the dynamic string of
Multiline_Output, is very similar to the label of Fl_Window
(indeed is like "TEST" + double). Confusing the two widget
pointer, it seems that the string of Fl_Window lives in
the heap region. Instead today i've found the correct
pointer to the label of Fl_Window, that point outside
the heap.
Sorry and thank you for the prompt replies :)
> > Second: is it the right way to release win (and it's child) with the call
> > in the destructor?
>
> Normally the way to do this would be to derive Test
> from Fl_Window, so that the widget's destructor gets
> called automatically. eg:
>
> class Test : public Fl_Window {
> Fl_Multiline_Output *output;
> public:
> Test(int X,int Y,int W,int H):Fl_Window(X,Y,W,H) {
> label("TEST");
> begin();
> output = new Fl_Multiline_Output(0,20,250,150);
> end();
> show();
> }
> ~Test() {
> // fltk will handle the widget destructions.
> // the only code you need here is to destroy non-fltk stuff,
> // which in this case is nothing
> }
> }
>
> That said, you can probably do it your way, perhaps someone
> else can weigh in on that.
>
Respect the second question; i'm new to gui programming,
so i've some doubt how to proceed! In my example is as if
the 'view' lives inside the 'model'! Deriving Fl_Window is
as if the 'model' lives inside the 'view' (IMHO). I've no
experience that gives me some hint about which of the two
is the best. But since already two person have suggested
to derive from Fl_Window, i will try this method ^^
Again, thank you everybody!
\o
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk