Initializer

init(rebasing:)

Creates a buffer over the same memory as the given buffer slice.

Declaration

init(rebasing slice: Slice<UnsafeBufferPointer<Element>>)

Parameters

slice

The buffer slice to rebase.

Discussion

The new buffer represents the same region of memory as slice, but is indexed starting at zero instead of sharing indices with the original buffer. For example:

let buffer = returnsABuffer()
let n = 5
let slice = buffer[n...]
let rebased = UnsafeBufferPointer(rebasing: slice)

After rebasing slice as the rebased buffer, the following are true:

  • rebased.startIndex == 0

  • rebased[0] == slice[n]

  • rebased[0] == buffer[n]

  • rebased.count == slice.count