Re: setting object data (how do I?)
- From: Paolo Molaro <lupus ximian com>
- To: gtk-perl <gtk-perl-list gnome org>
- Subject: Re: setting object data (how do I?)
- Date: Wed, 27 Jun 2001 16:55:54 +0200
On 06/27/01 Jim Edwards wrote:
Note, however, that every Gtk::Object is a hash reference and
^^^^^^^^^^^
you can use it to store data with the object itself:
$object->{mydata} = "stuff";
Either I've found a memory leak or you can't rely on this method:
In the initialization subroutine I have:
foreach $item (@{$list->{$gridtype}}) {
$snode =
$datatree->insert_node_defaults(parent=>$pnode,sibling=>$snode,titles=>[$item]);
$snode->{gridtype} = $gridtype;
print "$snode $item $gridtype\n";
}
$snode is not a Gtk::Object, so you should not use that technique.
Now the $text is correct, but the $node is a different memory location than that
originally assigned and gridtype is lost. I think that Gtk Perl uses hashs to
store it´s data but it doesn´t nessasarily keep them around, instead it relies
on the c side to do that. Can anyone confirm or deny this theory?:
Only types derived from Gtk::Object are guaranteed to be hash references
and you can safely store your data in them.
The other types may or may not work that way: this basically depends
on how the C library implements and memory-manages them, so don't
rely on that feature even for the misc objects that happen to support it.
GtkCTreeNode is a C struct that is not reference counted, so we
can't guarantee for how much time the data in it will be valid,
just use it and forget about it as soon as possible:-)
Oh, and you may bug the Gtk+ team so they provide more sensible interfaces
next time...
If you need to store data on a per-node basis, you have two
alternatives:
*) use set_row_data(), get_row_data(), but note that the data must be
a reference
*) add an additional (hidden) column and store your data as text in it.
lupus
--
-----------------------------------------------------------------
lupus debian org debian/rules
lupus ximian com Monkeys do it better
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]