On Fri, Mar 17, 2006 at 12:35:47AM +0100, Andreas Kotowicz wrote:
> so I have
> 
> typedef struct _FooApp
> {
>   gchar *app_name;
> 
>   GtkWidget *main_window;
>   .
>   .
> } FooApp;
> 
> which I use like this:
> 
> FooApp *
> create_app (void)
> {
>   FooApp *app;
> 
>   app = g_new0 (FooApp, 1);
> 
>   app->app_name = g_strdup ("My Foo App");
>   app->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>   .....
> }
> 
> now somewhere in my callbacks I want to create a messagebox:
> 
> void game_over(void *data)
> {
> 
>     FooApp *app = (FooApp*)data;
>     GtkWidget *msgBox;
>     
>     gchar* message;
>     message = g_strdup_printf("GAME OVER") ;
> 
>     msgBox = gtk_message_dialog_new(GTK_WINDOW(app->main_window),
> GTK_DIALOG_DESTROY_WITH_PARENT,
>     GTK_MESSAGE_WARNING,GTK_BUTTONS_CLOSE,message);
> 
> g_signal_connect_swapped(msgBox,"response",G_CALLBACK(destroy_game_over_cb),msgBox);
>     
>     gtk_widget_show_all(msgBox);
>     g_free (message);
> }
> 
> 
> but calling this messagebox I also want to modify some elements of app.

So why do you pass msgBox as *both* the object to connect to
and user_data to g_signal_connect_swapped() instead of just
passing app as user_data?

> 
> BTW, is there any difference in memory usage if I use
> 
>     gchar* message;
>     message = g_strdup_printf("GAME OVER") ;
> 
>     msgBox = gtk_message_dialog_new(GTK_WINDOW(app->main_window),
> GTK_DIALOG_DESTROY_WITH_PARENT,
>     GTK_MESSAGE_WARNING,GTK_BUTTONS_CLOSE,message);
>     g_free (message);
> 
> 
> or 
> 
> 
>     msgBox = gtk_message_dialog_new(GTK_WINDOW(app->main_window),
> GTK_DIALOG_DESTROY_WITH_PARENT,
>     GTK_MESSAGE_WARNING,GTK_BUTTONS_CLOSE,"Game OVER");
> 
> ?

In the first case you allocate a useless copy of "GAME OVER"
just to free it again.

Yeti


--
That's enough.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to