Re: Custom TreeModel
- From: Emmanuel Rodriguez <emmanuel rodriguez gmail com>
- To: gtk-perl-list gnome org
- Subject: Re: Custom TreeModel
- Date: Mon, 18 Jan 2010 22:43:11 +0100
On Mon, Jan 18, 2010 at 1:10 AM, Aristotle Pagaltzis
<pagaltzis gmx de> wrote:
* Emmanuel Rodriguez <emmanuel rodriguez gmail com> [2010-01-17 23:00]:
> I'm guessing that the problem occurs because there's no other
> variable that holds a reference to the values stored in
> TreeIter. Once the method that builds the TreeIter returns the
> Perl scalars stored in the iter get reclaimed.
What prevents you from holding onto the strings you pass into the
TreeIter yourself?Â
Holding to the strings has the same issue as holding to the XmlNodes. I endup duplicating the model in memory and I don't know when you release them.
Â
> This is why I tend to believe that with a pure Perl tree things
> will work better as the nodes will still have a refcount of 1.
Youâre going to swap out the entire DOM, and go to a more memory-
hungry and slower approach, just because the strings arenât held
onto, and you arenât willing to hold onto them yourself? Thatâs
not what Iâd doâ but suit yourself I guessâ
Not only that but I will be swapping an XML DOM for an HTML tree! Rest reassured I haven't gone mad :)
What's happening is that I wanted was to implement a TreeModel for an XML::LibXML DOM tree. I need this for my XML application Xacobeo [1] [2] which uses XML::LibXML as it source.
My first intention was to do this is in Perl. As you can see from my previous emails I failed. At first I wasn't able to implement such a TreeModel in Perl, so I reverted to C for the same backend (libxml2). Once I saw that the C version worked I gave a second try to the Perl version and managed to do what I posted.
I now have 2 implementations of the same TreeModel in C and Perl. I will try to use the C version for my application as XML documents can have easily millions of nodes and C will be very useful here for its speed. So the Perl version is a bit useless for me at the moment. I figured that I didn't do this in vain and that I could share it with others.
My intention is now to understand what I did wrong in the script and to refactor it into a decent implementation of a TreeModel that can serve as an inspiration for any other Perl application. So far this mailing list has been of great help and I think that I understand what's going on.
Now that I know that's happening with the memory management I will rewrite the script so that the tree uses as it base a real Perl tree model. The choice of HTML is ramdon and I could use something else: files, perl data, JSON export, as long as there's a valid parent/child relationship and that the model is in pure Perl.
I'm assuming that if someone else will use a custom TreeModel in a Gtk2-Perl application that it will be for a pure Perl tree and not for a tree that's implemented in C. If that's the case the new Perl example or this thread might be of some help.
[1] Xacobeo git
http://github.com/potyl/xacobeo[2] Xacobeo Screenshots
http://code.google.com/p/xacobeo/Â
--
Emmanuel Rodriguez
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]