-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
feat: make Array.buffer public #1815
Conversation
Usually you don't need Buffer. You're need pointer to internal array data right? In this case Array and TypedArray provide |
But they are private, although the private modifier is currently invalid, but I hope that a public field can do this (and is documented), dataStart is also private |
"dataStart" is public but unsafe. basically all FFI interfaces which use AssemblyScript (Fastly/lucet, NEAR/wasmer and just standard WASI) use |
@@ -33,7 +33,7 @@ export class Array<T> { | |||
// `dataStart` (equals `buffer`) and `byteLength` (equals computed `buffer.byteLength`), but the | |||
// block is 16 bytes anyway so it's fine to have a couple extra fields in there. | |||
|
|||
private buffer: ArrayBuffer; | |||
readonly buffer: ArrayBuffer; | |||
private dataStart: usize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MaxGraey Isn't it private now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, good point. In ArrayBufferView it's currently public. So I guess better make this public as well and add @unsafe
decorator. @dcodeIO wdyt?
Do you mean always changetype first? |
Basically you could mimic |
Well, I have a new question now. What is the point of storing both buffer and dataStart in ArrayBufferView? dataStart is equivalent to buffer everywhere. Sorry, what's the meaning of this value? |
|
Well, it seems that the reason is quite complicated |
dataStart should be documented in index.d.ts and website. |
|
ArrayBuffer is often needed to pass arrays when interacting with host function, but only Array does not expose buffer properties. It is unacceptable to get the copy overhead of ArrayBuffer every time it is converted to other Array types.