Re: [gtk-list] basic question



Gottipati Aravind wrote:
> 
> Hi,
>          I have a very basic question regd gtk. I am going throught the gtk
> tutorials and am in the third tutorial.
> 
> In it the author creates uses a gtkwidget *button and creates a button
> and names it button1. He sets up signal handlers for it etc..
> He then creates a second button using the same widget *button and names it
> button2
> I somehow feel that this should destroy the first button and all that he has
> set up for it, (because thats how pointers work.. right) but I see that it
> doesn't work this way. can someone explain what's happening?
> thank you
> Aravind.
> 
> --
>  earth is 98% full ... please delete anyone you can.
> 
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null

Ok first things first: he doesn't name the button "button1". He attaches
a GtkLabel to it with as label "button1". You could do this your self
(create a button using gtk_button_new() and attach a label), this is
just a convienence function.

Ok then the real question. No this is not the way pointers works. A
pointer is a variable which holds a reference to a certain memory area.
If the reference points to something else, the memory area itself is not
deleted. (stupid example: if a trafic sign to a city is removed ,the
city itself is not ;-)).

In this example he doesn't need the pointer to the button anymore,
because this is stored by gtk, using gtk_signal_connect(). So he just
reuses the variabel. The memory reserved for the button still remains
reserverd until it's freed (this is done by gtk_widget_destroy() or at
the end of the program).


Following picture:


1)    button -------->    [MEMORY AREA FOR BUTTON1]


2)                        [MEMORY AREA FOR BUTTON1]
      button -------->    [MEMORY AREA FOR BUTTON2]

so just the reference is forgotten inside THIS function.

Jeroen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]