Best way to get to CAS/fetch-and-add on unboxed vectors?
Aleksey Khudyakov
alexey.skladnoy at gmail.com
Wed Nov 20 16:53:59 UTC 2013
On 20 November 2013 16:06, Ryan Newton <rrnewton at gmail.com> wrote:
> Since GHC 7.8 will now absorb the functionality that was previously only in
> the atomic-primops package, it would be great to start exposing this for the
> data structures people actually want to use: i.e. unboxed vectors rather
> than raw MutableByteArrays.
>
> I've been reading through the code of vector, thinking that I would release
> some kind of "vector-atomics" package. Alas, I don't see how that is
> possible. There's no way to get at the MutableByteArray associated with an
> unboxed vector.
>
> (1) I think the minimum that would be necessary would be to modify
> "Data/Vector/Unboxed/Base.hs", where the instances for the type family
> actually exist, to provide an additional instance for each "MVector s Foo"
> that records the fact that the vector has and can expose a MutableByteArray.
>
> (2) Alternatively, an "exposeMutableByteArray" function could be added to
> the existing Unbox class. But this would affect other third party Unbox
> instances out there in the world... Is there any interest insupporting
> Unbox instances that are NOT implemented as a MutableByteArray?
>
AFAIR unboxed vector of tuples are implemented as tuple of vectors so there're
many underlying vectors and array of () implemented as simple Int.
Whole point of unboxed vector is to give flexibility in representation of arrays
More information about the Libraries
mailing list