SE-0138: Add UnsafeRawBufferPointer and UnsafeMutableRawBufferPointer. #4954

Merged
merged 1 commit into from Sep 23, 2016

Projects

None yet

1 participant

@atrick
Member
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.

@atrick atrick SE-0138: Add UnsafeRawBufferPointer and UnsafeMutableRawBufferPointer.
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.
1cd8b1f
@atrick
Member
atrick commented Sep 23, 2016

@dabrahams Please review for Swift 3.

@atrick
Member
atrick commented Sep 23, 2016

@swift-ci please test.

@atrick atrick merged commit f70a2e0 into apple:master Sep 23, 2016

4 checks passed

Swift Test Linux Platform Build finished.
Details
Swift Test Linux Platform (smoke test)
Details
Swift Test OS X Platform Build finished. 43505 tests run, 0 skipped, 0 failed.
Details
Swift Test OS X Platform (smoke test)
Details
@atrick atrick added a commit to atrick/swift that referenced this pull request Sep 23, 2016
@atrick atrick SE-0138: Add UnsafeRawBufferPointer and UnsafeMutableRawBufferPointer. (
#4954)


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.
1e86ede
@atrick atrick added a commit to atrick/swift that referenced this pull request Sep 27, 2016
@atrick atrick SE-0138: Add UnsafeRawBufferPointer and UnsafeMutableRawBufferPointer. (
#4954)


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.
734d396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment