About unsafeThaw and unsafeFreeze efficiency ....
Simon Marlow
simonmar at microsoft.com
Wed Nov 5 10:29:33 EST 2003
> "unsafeThaw :: (Ix i, IArray a e, MArray b e m) => a i e -
> > m (b i e)
> Converts an immutable array into a mutable array without
> taking a copy. This function is "unsafe" because any
> subsequent modifications made to the mutable version of
> the array will be shared with the immutable version. It
> is safe to use, therefore, if the immutable version is
> never referenced
> again. "
The documentation is a bit misleading. It should say something like:
Converts an immutable array into a mutable array. The
implementation may either simply cast the array from
one type to the other without copying the array, or it
may take a full copy of the array. The non-copying
implementation is supported between certain pairs of
array types only; one constraint is that the array
types must have identical representations. The following
pairs of array types have a non-copying O(1) implementation
of unsafeThaw:
* UArray -> IOUArray
* UArray -> STUArray
* Array -> IOArray
* Array -> STArray
Note that because the array is possibly not copied, any subsequent
modifications made to the mutable version of the array may be
shared with the immutable version. It is safe to use, therefore, if
the immutable version is never referenced again.
Note in particular that unsafeThaw to a StorableArray currently doesn't
have an efficient implementation.
I'll update the docs with the text above.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list