[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: GObject -- Initializing and finalizing



Lopaka Lee wrote:

>1) How can we set up a class finalizing function for static types?
>
>The type system issues a warning when a class_finalize function is
>specified during the registration of a static type.
>
>However, I have class-wide resources that should be freed when the
>instance ref count reaches zero -- to keep track of ref counts myself
>seems silly, given that the type system already does that.
>
Decription here:
    
http://developer.gnome.org/doc/API/2.0/gobject/gobject-GType.html#GClassInitFunc

Says that you should use the Base-init/finalize functions for
allocated resources on the the class.

>2) "Chaining up"
>
>When we override the parent class finalizing function, do we always need
>to store a pointer to the parent class?  Won't g_type_class_peek_parent()
>return the parent class (negating the need to store a pointer)?
>  
>
I'm guessing that this common practice of keeping a static file-scope 
pointer to
the parent class is just because allocating a 4-byte memory space to 
store it
costs way less than looking up an integer "type identifier" in a list; 
finding
its parent in the list and then returning a reference (which is also a 
short
proceedure but what the hey ;-)

>3) What is the use of the "gpointer data" parameter in class and instance
>init/finalize functions?
>  
>
I can't tell you the "reason why" as I didn't write the typedef itself;
but I can tell you that I always prototype it like this:
    static void project_type_class_init(type *project_type_class);
and the example code that follows the afore mentioned link; also
doesn't use any `class_data' argument.

Hmmm,
    I'm not a specialist on the execution stack but as a wild guess:

    if I call a function like this:
        project_type_class_init(class, class_data);

    and the actual stub is declared as such:
        void project_type_class_init(type *project_type_class) { 
gpointer a; /* ... code ...*/}

Then does the variable `a' get the value of the passed pointer 
`class_data' ?
or; I guess a less naive question is:

    "does the `class_data' argument overwrite anything important when it
/does/ get loaded on the execution stack" ?

Cheers,
                                        -Tristan





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]