Browse thread
Memory allocation nano-benchmark.
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Frédéric_Gava <frederic.gava@w...> |
| Subject: | Re: [Caml-list] Memory allocation nano-benchmark. |
Peraps test the following code (I do not have test it)
> let tmp1=Array.create tablesize 0 in
> let tmp2 = Array.create tablesize (Array.copy tmp1) in
> let table = Array.create tablesize (Array.copy tmp2) in
> for i = 0 to tablesize - 1 do
> for j = 0 to tablesize - 1 do
> for k = 0 to tablesize - 1 do
> table.(i).(j).(k) <- (i+1)*(j+1)*(k+1)
> done done done
> (copy are used to not have the same arrays )
Oups !!!!
The "Array.copy" is here a bug because we would do not have copies of the
arrays. A better code would be:
let table = Array.create tablesize [| [| |] |] in
(* modify the array table to not have arrays*)
for i=0 to tablesize - 1 do
table.(i) <- ( let tmp=Array.create tablesize [||] in
for j=0 to tablesize -1 do
tmp.(j) <- Array.create tablesize 0
done;
tmp)
done;
(* create the good values *)
for i = 0 to tablesize - 1 do
for j = 0 to tablesize - 1 do
for k = 0 to tablesize - 1 do
table.(i).(j).(k) <- (i+1)*(j+1)*(k+1)
done done done
I do not have test this code (I do not used my computer) but it does not
create closures.
Regards,
Frédéric Gava