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
Use fixed-length byte array rather than ByteArrayOutputStream
Reading out of a `ByteArrayOutputStream`
----------------------------------------
There's no properly supported way to get the ultimate cumulative byte
array stored in a `ByteArrayOutputStream` without doing an array copy -
that's what `ByteArrayOutputStream.toByteArray()` does, and that means:
* While copying, the JVM heap must briefly hold both the old & new byte arrays -
roughly speaking, doubling the memory requirements.
* Copying the bytes from one array to another takes a little bit of CPU time
(obviously this varies: `System.arraycopy()` for 40MB of bytes takes ~2ms
on my M1 machine).
Writing into a `ByteArrayOutputStream`
--------------------------------------
The new `KnownLengthStore` implementation does 1 array copy for a write.
The `BaosStore` implementation:
* Allocates a new array 'X' with the size of the new incoming data chunk
* Copies data into that array 'X'
* Copies array 'X' into the instance's cumulative byte array
Copy file name to clipboardExpand all lines: src/main/java/com/madgag/aws/sdk/async/responsebytes/awssdk/core/internal/async/ByteArrayAsyncResponseTransformerAlternative.java
0 commit comments