Re: more questions on struct, variables and objects
- From: "David Necas (Yeti)" <yeti physics muni cz>
- To: Andreas Kotowicz <kotoml mynetix de>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: more questions on struct, variables and objects
- Date: Fri, 17 Mar 2006 01:20:11 +0100
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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]