Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export Typed.part' #27

Closed
jamesdbrock opened this issue Feb 24, 2020 · 6 comments
Closed

export Typed.part' #27

jamesdbrock opened this issue Feb 24, 2020 · 6 comments
Assignees

Comments

@jamesdbrock
Copy link
Member

The Typed.part function takes an Index as its second argument, in units of the number of typed elements. What if we want to make an ArrayView which doesn't start in the ArrayBuffer at a typed element boundary?

https://github.com/jacereda/purescript-arraybuffer/blob/7f90bc44247dcbeab70caef5d373833286468266/src/Data/ArrayBuffer/Typed.purs#L137-L137

I think this library should also export the Typed.part' function, which is the same but with a ByteOffset type for the second argument.

@athanclark
Copy link
Collaborator

@jamesdbrock could you propose an expected type signature? I'm not sure if I completely understand what you're asking for.

@jamesdbrock
Copy link
Member Author

jamesdbrock commented Feb 24, 2020

@jamesdbrock
Copy link
Member Author

Oh, I've been assuming that I could work with DataView and ArrayView on the same ArrayBuffer, but that's not really how this is supposed to work, is it? DataView is for network transport. ArrayView is for buffers that stay on the local machine.

I can see now that probably no-one would ever want to construct a non-aligned ArrayView.

@athanclark
Copy link
Collaborator

I mean, it might make sense. I personally share an ArrayBuffer between multiple DataViews and ArrayViews often. ArrayBuffer is just a reference to some mutable state, like an STRef that you can't read or write to, because it's not formatted. DataView gives you manual set and read functions, based on specific byte-wise indexes, but only with one value at a time. However, an ArrayView gives you a typed interface to an ArrayBuffer for the whole thing, acting as a typed array for a specific numeric type.

If I recall correctly, there is a way to slice into ArrayBuffers, giving you a new one to the same piece of memory, so you could offset manually like that, but I don't actually see an issue with what you're proposing. The thing is, though, this library should be a lightweight layer on top of the native interface javascript provides. I'll have to dig a little, but I'll try to get this idea fleshed out.

@athanclark athanclark self-assigned this Feb 26, 2020
@jamesdbrock
Copy link
Member Author

Cool, thanks for maintaining this library, it's really nice.

@athanclark
Copy link
Collaborator

Wow I feel silly, I forgot this is actually a component of the library's FFI already x_x I'm exposing it now, sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants