Re: [Vala] Some implementation questions
- From: Hans Vercammen <hveso3 gmail com>
- To: gege2061 <gege2061 redaction-developpez com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Some implementation questions
- Date: Mon, 21 Jan 2008 16:19:49 +0100
Hi,
- Why Glib.Object inheritace is not implicit ?
Quoted Jürg:
While most classes (should) derive from GObject, it's not always the
case. For one there are many libraries that don't use GObject at all or
don't use GObject for all class types and we want to be able to use such
libraries from Vala. Examples include GLib itself, cairo, libxml2, and
many more.
There are also some rare cases where you want to define non-GObject in
Vala, either for performance reasons (when you need to create hundred
thousands of instances in short time) or if you need more control about
the field layout. You can also define new foundation types in Vala by
deriving from GLib.TypeInstance, such types can be used as lightweight
objects, that's what GStreamer does with GstMiniObject.
The difference between structs and classes in Vala is that structs are
value-types and classes are reference-types, as documented in the
reference manual[1]. That's the same as in C#.
In previous versions of Vala all classes derived from GObject; there was
an attribute to mark a struct as a (non-GObject) reference type. However
it was very confusing that some structs were value-types and other
structs were reference-types. While the current solution requires you to
type an extra ": Object" from time to time (compare that to the C
boilerplate), the approach makes a lot more sense, in my opinion.
- Why do not use g_type_class_add_private for class private members ?
This should normally be the case when you derive from GLib.Object
- For free memory object, use o->free(), why do not use delete keyword ?
Each allocated class should also have its own dispose function to free
allocated members and itself. Classes which are not derived from
GLib.Object are allocated by g_slice_new and should be freed with
g_slice_free.
Hope this answers your questions.
Hans
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]