From: Axel S. <A....@ke...> - 2004-01-08 17:46:12
|
On Thu, Jan 08, 2004 at 08:19:11AM -0800, JP Bernardy wrote: > > Could you shed some light on how you are using the > > GdkRGB functions? If > > these functions are much simpler in your case, maybe > > we bind them and warn > > the user about the Ptr problem. > > Here is how I wrapped the thing: > > renderFrame ... = > do > dat :: [Word32] > let dat = ... (computed graphic data) > mem <- newArray dat > drawRgb32Image win gc 0 0 width height > RgbDitherNone mem (width*4) > free mem > > Nothing fancy... I thought that the correctness is > guaranteed by the sequential nature of IO actions. It is correct, but you have to keep track of the memory yourself. Two suggestions: a) If your > let dat = ... (computed graphic data) calculation consists of plain rectangles, lines or points then you can get away with creating some graphics contexts (GC) and use the drawing functions. b) If you do fancy color juggling, then you really want to generate arrays of words and let Gtk allocate all the colors. Would it be useful to have the function http://developer.gnome.org/doc/API/2.0/gdk-pixbuf/gdk-pixbuf-creating.html#gdk-pixbuf-new-from-data as pixbufNewFromData :: [Word32] -> Colorspace -> Bool -> .... in Haskell. That way we can move the allocation of the array into the library and the user wouldn't have to worry about it. > Grossly inefficient however since I need to allocate a > lot of memory for each rendered frame. > > Fixing that probably requires the reference counting > machinery that you've described. However, I can't see > how a pixbuf solves this: I can't get a pointer to the > pixbuf pixels data... Or can I? The only way to avoid this is to reuse the C allocated memory region. Then the GdkRGB functions are probably the only way out. Axel. |