Version française
Home     About     Download     Resources     Contact us    
Browse thread
Big array with data managed by another value
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel_Bünzli <daniel.buenzli@e...>
Subject: Re: [Caml-list] Big array with data managed by another value

Le 14 nov. 08 à 16:58, Romain Beauxis a écrit :

> Yep, that's my current solution.

Another less friendly solution is to provide the bigarray in a  
callback and document the fact that the bigarray is only valid for the  
call and should not escape the scope.

val with_bigarray : custom -> (bigarray -> 'a) -> 'a

let with_bigarray c f =
   let ba = barray_of c in
   try let r = f ba in barray_invalidate ba; r with e ->  
barray_invalidate ba; raise e

barray_invalidate should set the bigarray size to 0 so that if the  
client doesn't respect the policy it will only get an out of bounds  
error (unless he compiled with -unsafe).

Best,

Daniel