Shodan82
asked on
Gtk - Inheritance of GtkWindow
Been fiddling around with inheritance in Gtk and figured I'd make a MainWindow class. This works well except it sucks a lot of memory (around 6MB) with the code below. Just creating a new window in main() uses about 2.5MB. Any ideas why?
Also, is it a bad idea to inherit from GtkWindow and create the application around a MainWindow? Because I haven't seen many apps do it this way. Examples would be great.
Thanks
Also, is it a bad idea to inherit from GtkWindow and create the application around a MainWindow? Because I haven't seen many apps do it this way. Examples would be great.
Thanks
/* main.c */
#include <gtk/gtk.h>
#include "window.h"
gint main(gint argc, gchar *argv[])
{
g_thread_init(NULL);
gtk_init(&argc, &argv);
GtkMainWindow* main_window;
main_window = (GtkMainWindow*)gtk_main_window_new();
gtk_widget_show(GTK_WIDGET(main_window));
gtk_main();
return 0;
}
/* window.h */
#ifndef WINDOW_H
#define WINDOW_H
#include <gtk/gtk.h>
#define GTK_MAIN_WINDOW_TYPE (gtk_main_window_get_type ())
#define GTK_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_MAIN_WINDOW_TYPE, GtkMainWindow))
#define GTK_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_MAIN_WINDOW_TYPE, GtkMainWindowClass))
#define IS_GTK_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_MAIN_WINDOW_TYPE))
#define IS_GTK_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_MAIN_WINDOW_TYPE))
typedef struct _GtkMainWindow GtkMainWindow;
typedef struct _GtkMainWindowClass GtkMainWindowClass;
struct _GtkMainWindow
{
GtkWindow parent;
};
struct _GtkMainWindowClass
{
GtkWindowClass parent_class;
};
GtkType gtk_main_window_get_type(void);
GtkWidget* gtk_main_window_new(void);
#endif
/* window.c */
#include "window.h"
static void gtk_main_window_class_init (GtkMainWindowClass *klass)
{
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
}
static void gtk_main_window_init(GtkMainWindow* mw)
{
}
GType gtk_main_window_get_type(void)
{
static GType type = 0;
if (!type)
{
static const GTypeInfo info =
{
sizeof (GtkMainWindowClass),
NULL,
NULL,
(GClassInitFunc)gtk_main_window_class_init,
NULL,
NULL,
sizeof (GtkMainWindow),
0,
(GInstanceInitFunc)gtk_main_window_init,
};
type = g_type_register_static(GTK_TYPE_WINDOW, "GtkMainWindow", &info, 0);
}
return type;
}
GtkWidget* gtk_main_window_new()
{
return GTK_WIDGET(gtk_type_new(gtk_main_window_get_type()));
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.