{"action":"created","issue":{"url":"https://api.github.com/repos/WebAssembly/design/issues/1162","repository_url":"https://api.github.com/repos/WebAssembly/design","labels_url":"https://api.github.com/repos/WebAssembly/design/issues/1162/labels{/name}","comments_url":"https://api.github.com/repos/WebAssembly/design/issues/1162/comments","events_url":"https://api.github.com/repos/WebAssembly/design/issues/1162/events","html_url":"https://github.com/WebAssembly/design/issues/1162","id":279510172,"number":1162,"title":"Zero-copy pass ArrayBuffer from JS-land to WebAssembly-land","user":{"login":"alexhultman","id":3397140,"avatar_url":"https://avatars1.githubusercontent.com/u/3397140?v=4","gravatar_id":"","url":"https://api.github.com/users/alexhultman","html_url":"https://github.com/alexhultman","followers_url":"https://api.github.com/users/alexhultman/followers","following_url":"https://api.github.com/users/alexhultman/following{/other_user}","gists_url":"https://api.github.com/users/alexhultman/gists{/gist_id}","starred_url":"https://api.github.com/users/alexhultman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexhultman/subscriptions","organizations_url":"https://api.github.com/users/alexhultman/orgs","repos_url":"https://api.github.com/users/alexhultman/repos","events_url":"https://api.github.com/users/alexhultman/events{/privacy}","received_events_url":"https://api.github.com/users/alexhultman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-12-05T19:59:46Z","updated_at":"2017-12-05T20:53:19Z","closed_at":null,"author_association":"NONE","body":"Hey,\r\n\r\nFrom reading about the WebAssembly.Memory there really is no way to pass an ArrayBuffer zero-copy to C++ from JS.\r\n\r\nExample:\r\n\r\nLet's say a WebSocket in the browser triggers the onmessage with an ArrayBuffer of the message data. Now I want to read this data in C++. From all solutions I've seen you really need to:\r\n\r\n1. allocate a new WebAssembly.Memory (or whatever allocation strategy you use)\r\n2. copy the contents of ArrayBuffer with the message to the ArrayBuffer of the WebAssembly.Memory\r\n3. call into C++ and use the copied memory as char *\r\n4. free the WebAssembly.Memory\r\n\r\nImagine having a constructor like new WebAssembly.Memory(ArrayBuffer) so that you could skip all steps except for step 3.\r\n\r\nDid I get something wrong or is this not supported?"},"comment":{"url":"https://api.github.com/repos/WebAssembly/design/issues/comments/349437979","html_url":"https://github.com/WebAssembly/design/issues/1162#issuecomment-349437979","issue_url":"https://api.github.com/repos/WebAssembly/design/issues/1162","id":349437979,"user":{"login":"lukewagner","id":9660325,"avatar_url":"https://avatars1.githubusercontent.com/u/9660325?v=4","gravatar_id":"","url":"https://api.github.com/users/lukewagner","html_url":"https://github.com/lukewagner","followers_url":"https://api.github.com/users/lukewagner/followers","following_url":"https://api.github.com/users/lukewagner/following{/other_user}","gists_url":"https://api.github.com/users/lukewagner/gists{/gist_id}","starred_url":"https://api.github.com/users/lukewagner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukewagner/subscriptions","organizations_url":"https://api.github.com/users/lukewagner/orgs","repos_url":"https://api.github.com/users/lukewagner/repos","events_url":"https://api.github.com/users/lukewagner/events{/privacy}","received_events_url":"https://api.github.com/users/lukewagner/received_events","type":"User","site_admin":false},"created_at":"2017-12-05T20:53:19Z","updated_at":"2017-12-05T20:53:19Z","author_association":"OWNER","body":"You're right that many Web APIs now incur extra copying overhead that we should work to remove.\r\n\r\nThe problem with what you've proposed is that WebAssembly engines often want to have special representations (extra guard pages, page-aligned allocation) for `Memory` which means you can't take an arbitrary `ArrayBuffer` and, without making a copy, convert it into a `Memory`.\r\n\r\nI think a better way to achieve zero-copy is if, instead of allocating *new* `ArrayBuffer`s as return values, Web APIs provided functions that took typed array views (or, to avoid view garbage, an `ArrayBuffer`, offset, and length) as input parameters into which the outputs were written."}}
{"actor":{"display_login":"lukewagner"}}