Skip to content
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

Allow aliasing between read-only buffers #12204

Merged
merged 1 commit into from
Mar 22, 2022
Merged

Conversation

chrisvest
Copy link
Contributor

Motivation:
Aliasing is only a problem when mutation is involved.
Since making a buffer read-only is irreversible, we can permit them to share the underlying memory.

Modification:
Add a Buffer.copy method that takes an argument for whether the resulting buffer should be read-only or not.
If both original and copy buffers are read-only, then reuse the existing structural sharing mechanics of the const buffers, to make both read-only buffers share the same underlying memory.

Result:
Copying read-only buffers can now offer a useful optimisation.

Motivation:
Aliasing is only a problem when mutation is involved.
Since making a buffer read-only is irreversible, we can permit them to share the underlying memory.

Modification:
Add a `Buffer.copy` method that takes an argument for whether the resulting buffer should be read-only or not.
If both original and copy buffers are read-only, then reuse the existing structural sharing mechanics of the const buffers, to make both read-only buffers share the same underlying memory.

Result:
Copying read-only buffers can now offer a useful optimisation.
@normanmaurer normanmaurer merged commit 5f675bb into netty:main Mar 22, 2022
@normanmaurer normanmaurer added this to the 5.0.0.Alpha2 milestone Mar 22, 2022
@chrisvest chrisvest deleted the 5x-copy-ro branch March 22, 2022 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants