Gtk - Inheritance of GtkWindow

Shodan82
Shodan82 used Ask the Experts™
on
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
/* 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()));
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CEO/Programmer
Commented:
You don't use inheritance that way in GTK. You "use the" exsiting stuff but do  not inherit.
I suggest you download glade build some simple applicaton and look  at the  code.
However the GTK window has a lot of things "built-in" so it must have a considerable size. The point is that you can  not conclude
1) if a windows is that big
2) the applicaton itself must be a code monster.

The point is you have to carry all the base stuff with you. So I'd expect that just adding a few things does not really make much on the size on the program, of course a fully fledged program may be much larger but you can check. Just see how large some gtk application really are...

I guess one of the largest will be the GIMP, check how large that is and you can "be sure" that everything you'll write will be "smaller" ....

Regards
Friedrich

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial