Skip to content

SE-0138: Add UnsafeRawBufferPointer and UnsafeMutableRawBufferPointer. #4954

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

Merged
merged 1 commit into from
Sep 23, 2016
Merged

SE-0138: Add UnsafeRawBufferPointer and UnsafeMutableRawBufferPointer. #4954

merged 1 commit into from
Sep 23, 2016

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Sep 23, 2016

https://github.com/apple/swift-evolution/blob/master/proposals/0138-unsaferawbufferpointer.md

Unsafe[Mutable]RawBufferPointer is a non-owning view over a region of memory as
a Collection of bytes independent of the type of values held in that
memory. Each 8-bit byte in memory is viewed as a UInt8 value.

Reads and writes on memory via Unsafe[Mutable]RawBufferPointer are untyped
operations. Accessing this Collection's bytes does not bind the
underlying memory to UInt8. The underlying memory must be bound
to some trivial type whenever it is accessed via a typed operation.

In addition to the Collection interface, the following methods from
Unsafe[Mutable]RawPointer's interface to raw memory are
provided with debug mode bounds checks: load(fromByteOffset:as:),
storeBytes(of:toByteOffset:as:), and copyBytes(from:count:).

This is only a view into memory and does not own the memory. Copying a value of
type UnsafeMutableRawBufferPointer does not copy the underlying
memory. Assigning an Unsafe[Mutable]RawBufferPointer into a value-based
collection, such as [UInt8] copies bytes out of memory. Assigning into a
subscript range of UnsafeMutableRawBufferPointer copies into memory.

https://github.com/apple/swift-evolution/blob/master/proposals/0138-unsaferawbufferpointer.md

Unsafe[Mutable]RawBufferPointer is a non-owning view over a region of memory as
a Collection of bytes independent of the type of values held in that
memory. Each 8-bit byte in memory is viewed as a `UInt8` value.

Reads and writes on memory via `Unsafe[Mutable]RawBufferPointer` are untyped
operations. Accessing this Collection's bytes does not bind the
underlying memory to `UInt8`. The underlying memory must be bound
to some trivial type whenever it is accessed via a typed operation.

In addition to the `Collection` interface, the following methods from
`Unsafe[Mutable]RawPointer`'s interface to raw memory are
provided with debug mode bounds checks: `load(fromByteOffset:as:)`,
`storeBytes(of:toByteOffset:as:)`, and `copyBytes(from:count:)`.

This is only a view into memory and does not own the memory. Copying a value of
type `UnsafeMutableRawBufferPointer` does not copy the underlying
memory. Assigning an `Unsafe[Mutable]RawBufferPointer` into a value-based
collection, such as `[UInt8]` copies bytes out of memory. Assigning into a
subscript range of UnsafeMutableRawBufferPointer copies into memory.
@atrick
Copy link
Contributor Author

atrick commented Sep 23, 2016

@dabrahams Please review for Swift 3.

@atrick
Copy link
Contributor Author

atrick commented Sep 23, 2016

@swift-ci please test.

@atrick atrick merged commit f70a2e0 into swiftlang:master Sep 23, 2016
MaxDesiatov pushed a commit that referenced this pull request Sep 7, 2023
[pull] swiftwasm from main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant