I've have modified the DynArray module so it does not need anymore a null
value. The only (small) tradeoff is that float dynarrays are boxed and that
we need to copy element-by-element from and to float arrays instead of using
Array primitives who must be faster.
I have some idea for keeping the float arrays unboxed but I might lead to a
more complex code and will surely trade space for speed since we will need
to do some tests in most of the calls. Here's the source code, any
comments/tests grealty apprecied before commit.
I also fixed some bugs on the way , and I'm currently wondering why the
resizer function is called every time we add/insert an element , even is
there is space available ? this should be corrected.
If I understand correctly, the problem is that using "Obj.magic 0" as
a null causes a segfault. It is because de-reference occurs when
inserting floats into float arrays.
If it is true, then Michal Moskal's approach seems most elegant to
me. (using "ref 0.0" as a null value.) If relying the fact that
references and boxed floats are same structures is not acceptable, you
can test whether the given array is a float array by looking its block
tag. The test is needed only in creation and resizing. (Though you
may think theses options already.)
From: Nicolas Cannasse <warplayer@fr...> - 2003-06-25 09:26:03
> If I understand correctly, the problem is that using "Obj.magic 0" as
> a null causes a segfault. It is because de-reference occurs when
> inserting floats into float arrays.
The tag of the array saying it can be Double_array or 0 (normal array)
depends on the init value you create it with : if the value have the
Double_val tag then we're creating a (unboxed) float array.
In fact, you can create a boxed float array just by calling :
let fa = (Obj.magic (Array.make n 0) : float array)
that will work correctly, since insertion will test for the Double_array_tag
of the array, and not test for the inserted element tag.
But hold your breath , I'm currently working on a far better version that
doesn't need any more Obj.magic and that is working with an abstract type
which is in fact a raw ocaml block with tag 0 (exactly the same as an array,
but never makes test for Double_array_tag nor bounds checking : better since
we're already testing them in the DynArray library).
From: John Max Skaller <skaller@oz...> - 2003-06-27 11:13:09
Nicolas Cannasse wrote:
> Hi !
> I've have modified the DynArray module so it does not need anymore a null
> value. The only (small) tradeoff is that float dynarrays are boxed and that
> we need to copy element-by-element from and to float arrays instead of using
> Array primitives who must be faster.
I think this is a good start: it gets the interface right.
It is probably worth showing the Ocaml team, and asking what
they'd do to support unboxed arrays. Note that floats won't
be the only unboxed arrays, there's a good chance the team
is working to unbox all arrays of scalar types.
John Max Skaller, mailto:skaller@...
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
Get latest updates about Open Source Projects, Conferences and News.