You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 24, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+3-44Lines changed: 3 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Champion: Shu-yu Guo (@syg)
8
8
9
9
## Introduction
10
10
11
-
`ArrayBuffer`s have enabled in-memory handling of binary data and have enjoyed great success. This proposal extends the `ArrayBuffer` constructors to take an additional maximum length that allows in-place growth and shrinking of buffers. Similarly, `SharedArrayBuffer` is extended to take an additional maximum length that allows in-place growth. The `transfer` method is also re-introduced here as a standard way to detach `ArrayBuffer`s, perform zero-copy moves, and to "fix" resizable `ArrayBuffer` instances to `ArrayBuffer` instances.
11
+
`ArrayBuffer`s have enabled in-memory handling of binary data and have enjoyed great success. This proposal extends the `ArrayBuffer` constructors to take an additional maximum length that allows in-place growth and shrinking of buffers. Similarly, `SharedArrayBuffer` is extended to take an additional maximum length that allows in-place growth.
12
12
13
13
## Motivation and use cases
14
14
@@ -62,19 +62,6 @@ class ArrayBuffer {
62
62
// - Throws a RangeError if byteLength > maxByteLength.
63
63
constructor(byteLength [, options ]);
64
64
65
-
// Returns a *non*-resizable ArrayBuffer with the same byte content
66
-
// at this buffer for [0, min(this.byteLength, newByteLength)],
67
-
// then detaches this buffer.
68
-
//
69
-
// Any new memory is zeroed.
70
-
//
71
-
// If newByteLength is undefined, it is set to this.bytelength.
72
-
//
73
-
// Designed to be implementable as a copy-free move or a realloc.
74
-
//
75
-
// Throws a RangeError unless 0 <= newByteLength.
76
-
transfer(newByteLength);
77
-
78
65
// Resizes the buffer.
79
66
//
80
67
// Grows are designed to be implemented in-place, i.e. address space is
@@ -109,30 +96,6 @@ class ArrayBuffer {
109
96
}
110
97
```
111
98
112
-
`ArrayBuffer#transfer` may be used to "fix" resizable buffers in a zero-copy move to normal `ArrayBuffer`s.
113
-
114
-
Example:
115
-
116
-
```javascript
117
-
let rab =newArrayBuffer(1024, { maxByteLength:1024**2 });
118
-
assert(rab.byteLength===1024);
119
-
assert(rab.maxByteLength===1024**2);
120
-
assert(rab.resizable);
121
-
122
-
rab.resize(rab.byteLength*2);
123
-
assert(rab.byteLength===1024*2);
124
-
125
-
// Transfer the first 1024 bytes.
126
-
let ab =rab.transfer(1024);
127
-
// rab is now detached
128
-
assert(rab.byteLength===0);
129
-
assert(rab.maxByteLength===0);
130
-
131
-
// The contents are moved to ab.
132
-
assert(!ab.resizable);
133
-
assert(ab.byteLength===1024);
134
-
```
135
-
136
99
### `SharedArrayBuffer`
137
100
138
101
```javascript
@@ -291,10 +254,6 @@ Growing a growable `SharedArrayBuffer` performs a SeqCst access on the buffer le
291
254
292
255
This aligns with WebAssembly as well as enable more optimization opportunities for bounds checking codegen. It also means that other threads are not guaranteed to see the grown length without synchronizing on an explicit length access, such as by reading the `byteLength` accessor.
293
256
294
-
### Is `transfer` realloc?
295
-
296
-
Yes, with detach semantics.
297
-
298
257
## Open questions
299
258
300
259
### Should `resize(0)` be allowed?
@@ -303,9 +262,9 @@ Yes, with detach semantics.
303
262
304
263
https://github.com/tc39/proposal-resizablearraybuffer/issues/22 points out that `ArrayBuffer(0)` is already a thing. This proposal thus allows `resize(0)`.
305
264
306
-
### Should there be a `transferResizable()` that reallocs into another resizable `ArrayBuffer`?
265
+
### What happened to `transfer()`? It used to be here.
307
266
308
-
Are there compelling use cases for this?
267
+
It has been separated into its own proposal to further explore the design space. New proposal repo TBD.
0 commit comments