Correct use of pixbuf, pixmap, and image?


This is about the Gtk2::Ex::Geo modules, which are on CPAN. How the code works is, at least partly, explained also on

I've got a derivative (subclass in Perl sense) of Gtk2::Gdk::Pixbuf. I create it using gdk_pixbuf_new_from_data. The data is created in C using my own draw routines. From this pixbuf I create a pixmap by calling render_pixmap_and_mask in Gtk-Perl. And in the last step I create an Gtk2::Image by calling set_from_pixmap.

The image is used in a subclass of Gtk2::ScrolledWindow. Everything works. But there is somewhere a problem of wasting memory.

Creating the initial pixbuf may take a long time (seconds) and it is not possible to draw on a pixbuf, only on a pixmap. In my code I want to be able to re-use once created pixbuf. For example there is a dialog box, where the user may select a graphical object and it is highlighted by drawing it (with Gtk-Perl) on the pixmap. So every time the user selects a new object, this procedure is executed:

1. create pixmap from the initial pixbuf and set the pixmap into the image
2. draw on the pixmap
3. hide the ScrolledWindow
4. show the ScrolledWindow

I haven't seen a good documentation on some of the functions I use, so I've ended up to this procedure with some experimentation. I also don't understand well the client/server concept related to this (if the program is running over X, the pixmap is created on the client?). I just played with this and I believe the code is hogging memory when the above procedure is run multiple times. Does anybody have any ideas? About documentation.. I just found the Havoc Pennington's book on and I have Warkus' book. Are there other good sources?



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