[swift-evolution] [swift-evolution-announce] [Review] SE-0107: UnsafeRawPointer API

Andrew Trick atrick at apple.com
Tue Jul 5 14:12:09 CDT 2016


> On Jul 5, 2016, at 2:06 PM, Andrew Trick <atrick at apple.com> wrote:
> 
>> * I don't think I understand `initialize(toContiguous:atIndex:with:)`. Does it return a typed pointer to the whole buffer, or just the one instance it initialized? 


Typed pointers are returned only for the memory that was initialized. In this case, a single element:

  /// Initialize the memory location at `index` with `newValue` as if this
  /// memory holds at least `index` + 1 contiguous values of type `T`.
  ///
  /// Returns an `UnsafeMutablePointer<T>` the single intialized
  /// in-memory element.
  ///
  /// - Precondition: The memory at `index` is not initialized.
  ///
  /// - Precondition: The underlying pointer is properly aligned for
  ///                 accessing `T`.
  ///
  /// - Postcondition: The memory is initialized; the value should eventually
  ///   be destroyed or moved from to avoid leaks.
  @discardableResult
  public func initialize<T>(toContiguous _: T.Type, atIndex index: Int,
    with value: T)
    -> UnsafeMutablePointer<T> {
    return (self + strideof(T.self) * index).initialize(T.self, with: value)
  }

Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160705/a3cf76ec/attachment.html>


More information about the swift-evolution mailing list