Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 098ac26

Browse files
committed
Normative: Remove transfer
This method will be explored in its own proposal. See #113.
1 parent d2c7105 commit 098ac26

File tree

4 files changed

+45
-124
lines changed

4 files changed

+45
-124
lines changed

README.md

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Champion: Shu-yu Guo (@syg)
88

99
## Introduction
1010

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.
1212

1313
## Motivation and use cases
1414

@@ -62,19 +62,6 @@ class ArrayBuffer {
6262
// - Throws a RangeError if byteLength > maxByteLength.
6363
constructor(byteLength [, options ]);
6464

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-
7865
// Resizes the buffer.
7966
//
8067
// Grows are designed to be implemented in-place, i.e. address space is
@@ -109,30 +96,6 @@ class ArrayBuffer {
10996
}
11097
```
11198
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 = new ArrayBuffer(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-
13699
### `SharedArrayBuffer`
137100
138101
```javascript
@@ -291,10 +254,6 @@ Growing a growable `SharedArrayBuffer` performs a SeqCst access on the buffer le
291254
292255
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.
293256
294-
### Is `transfer` realloc?
295-
296-
Yes, with detach semantics.
297-
298257
## Open questions
299258
300259
### Should `resize(0)` be allowed?
@@ -303,9 +262,9 @@ Yes, with detach semantics.
303262
304263
https://github.com/tc39/proposal-resizablearraybuffer/issues/22 points out that `ArrayBuffer(0)` is already a thing. This proposal thus allows `resize(0)`.
305264
306-
### Should there be a `transferResizable()` that reallocs into another resizable `ArrayBuffer`?
265+
### What happened to `transfer()`? It used to be here.
307266
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.
309268
310269
## History and acknowledgment
311270

0 commit comments

Comments
 (0)