Question about ArrayArray#

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about ArrayArray#

Michal Terepeta
Hi all,

I have a quick question about ArrayArray#. Is it safe to store *both* an
ByteArray# and ArrayArray# within the *same* ArrayArray#? For instance:
- at index 0 of an ArrayArray# I store a different ArrayArray#,
- at index 1 of that same ArrayArray# I store a ByteArray#.

It seems to me that this should be safe/supported from the point of view of
the runtime system:
- both ArrayArray# and ByteArray# have the same kind/runtime representation,
- the arrays have a header that tells rts/GC what they are/how to handle
them.
(But I, as a user, would be responsible for using the right primop with the
right index to read them back)

Is this correct?

Thanks a lot!

- Michal
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Question about ArrayArray#

Carter Schonwald
I think Ed’s structs package explicitly makes use of this :)

On Wed, May 2, 2018 at 7:31 AM Michal Terepeta <[hidden email]> wrote:
Hi all,

I have a quick question about ArrayArray#. Is it safe to store *both* an
ByteArray# and ArrayArray# within the *same* ArrayArray#? For instance:
- at index 0 of an ArrayArray# I store a different ArrayArray#,
- at index 1 of that same ArrayArray# I store a ByteArray#.

It seems to me that this should be safe/supported from the point of view of
the runtime system:
- both ArrayArray# and ByteArray# have the same kind/runtime representation,
- the arrays have a header that tells rts/GC what they are/how to handle
them.
(But I, as a user, would be responsible for using the right primop with the
right index to read them back)

Is this correct?

Thanks a lot!

- Michal
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Question about ArrayArray#

Michal Terepeta
On Thu, May 3, 2018 at 2:40 PM Carter Schonwald <[hidden email]> wrote:
I think Ed’s structs package explicitly makes use of this :)

Oh, interesting! Thanks for the pointer!

Looking at Ed's code, he's seems to be doing something similar to that I'm also interested in: having a SmallArray# that at one index points to another SmallArray# and at another one to a ByteArray#.  (my use case involves multiple small arrays, so I'd rather use SmallArray# than ArrayArray#):

So I guess my second question becomes: is anyone aware of some rts/GC invariants/expectations that would be broken by doing this? (ignoring the issue of getting every `unsafeCoerce#` right :)

Thanks!

- Michal

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs