Request: withArrayLength

Adrian Hey ahey at
Wed Feb 11 04:55:00 EST 2004


The FFI currently provides..

 withArray :: Storable a => [a] -> (Ptr a -> IO b) -> IO b

I think..

 withArrayLength :: Storable a => [a] -> (Ptr a -> Int -> IO b) -> IO b

would be useful because you often need the length in a foreign function
and I guess withArray must pre-calculate the length before allocating
storage in any case (or at least must know the length by the time
marshalling is finished).

It seems a pity to waste time calculating it twice.

Actually, looking at the ffi again I see there is something similar
for CStrings already, but not for arrays in general. Is this an
oversight or a deliberate decision?

Adrian Hey

More information about the FFI mailing list