Skip to content

[docs] clarify docs for load, loadUnaligned and storeBytes #59187

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
Jun 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ extension Unsafe${Mutable}RawBufferPointer {
/// Returns a new instance of the given type, read from the buffer pointer's
/// raw memory at the specified byte offset.
///
/// The memory at `offset` bytes from this buffer pointer's `baseAddress`
/// must be properly aligned for accessing `T` and initialized to `T` or
/// another type that is layout compatible with `T`.
///
/// You can use this method to create new values from the buffer pointer's
/// underlying bytes. The following example creates two new `Int32`
/// instances from the memory referenced by the buffer pointer `someBytes`.
Expand Down Expand Up @@ -394,20 +398,18 @@ extension Unsafe${Mutable}RawBufferPointer {
/// underlying bytes. The following example creates two new `Int32`
/// instances from the memory referenced by the buffer pointer `someBytes`.
/// The bytes for `a` are copied from the first four bytes of `someBytes`,
/// and the bytes for `b` are copied from the next four bytes.
/// and the bytes for `b` are copied from the fourth through seventh bytes.
///
/// let a = someBytes.load(as: Int32.self)
/// let b = someBytes.load(fromByteOffset: 4, as: Int32.self)
/// let a = someBytes.loadUnaligned(as: Int32.self)
/// let b = someBytes.loadUnaligned(fromByteOffset: 3, as: Int32.self)
///
/// The memory to read for the new instance must not extend beyond the buffer
/// pointer's memory region---that is, `offset + MemoryLayout<T>.size` must
/// be less than or equal to the buffer pointer's `count`.
///
/// - Parameters:
/// - offset: The offset, in bytes, into the buffer pointer's memory at
/// which to begin reading data for the new instance. The buffer pointer
/// plus `offset` must be properly aligned for accessing an instance of
/// type `T`. The default is zero.
/// which to begin reading data for the new instance. The default is zero.
/// - type: The type to use for the newly constructed instance. The memory
/// must be initialized to a value of a type that is layout compatible
/// with `type`.
Expand Down Expand Up @@ -455,9 +457,7 @@ extension Unsafe${Mutable}RawBufferPointer {
/// - Parameters:
/// - value: The value to store as raw bytes.
/// - offset: The offset in bytes into the buffer pointer's memory to begin
/// reading data for the new instance. The buffer pointer plus `offset`
/// must be properly aligned for accessing an instance of type `T`. The
/// default is zero.
/// reading data for the new instance. The default is zero.
/// - type: The type to use for the newly constructed instance. The memory
/// must be initialized to a value of a type that is layout compatible
/// with `type`.
Expand Down