Problems with GDraw.pixmap lines method (f_pointarray)
Matthieu Dubuget <[email protected]> Tue, 10 Nov 2009 13:12:07 +0100
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I had random freeze in one of my application. (mingw, native, multithreaded)
The main application is multithreaded. I narrowed the problem in a
smaller (still too big to share) one,
without using threads at all. Let's call it miniapp.
Miniapp still freezes at a line like this one:
px#lines ln
px is a GDraw.pixmap, and ln was compressed to a list which length is no
more than 1000 elements.
When I replace "px#lines ln" with:
my_lines px ln;
I experience no more freeze.
Here is my_lines definition:
let my_lines (px:GDraw.pixmap) lns =
let rec ml = function
[] | _ :: [] -> ()
| (x1,y1) :: (x2, y2) :: tl ->
px#line ~x:x1 ~y:y1 ~x:x2 ~y:y2;
ml ((x2,y2)::tl) in
ml lns
Following GDraw.pixmap lines, it appears that this function calls
f_pointarray (gdk.ml).
This one in turn, creates and uses a PointArray.t
module PointArray = struct
type t = { len: int}
external create : len:int -> t = "ml_point_array_new"
external set : t -> pos:int -> x:int -> y:int -> unit =
"ml_point_array_set"
let set arr ~pos =
if pos < 0 || pos >= arr.len then invalid_arg "PointArray.set";
set arr ~pos
end
And here is what I found for ml_point_array_new in ml_gdk.c:
CAMLprim value ml_point_array_new (value len)
{
value ret;
if(Int_val(len) <= 0)
invalid_argument("PointArray.new");
ret = alloc (1 + Wosize_asize(Int_val(len)*sizeof(GdkPoint)),
Abstract_tag);
Field(ret,0) = len;
return ret;
}
Ok. A PointArray is a garbage collectable array, with the first element
containing it's length.
What could explain my problem? Maybe I'm calling this too often and
alloc as some problem to find place?
I'm going on with my supposed less efficient "my_lines", but I'd like to
understand the root of my problem.
Thanks in advance, an sorry for my poor english.
Matt