Swift Language(Unsafe) Buffer Pointers

Introduction

“A buffer pointer is used for low-level access to a region of memory. For example, you can use a buffer pointer for efficent processing and communication of data between apps and services.”

Excerpt From: Apple Inc. “Using Swift with Cocoa and Objective-C (Swift 3.1 Edition).” iBooks. https://itun.es/us/utTW7.l

You are responsible for handling the life cycle of any memory you work with through buffer pointers, to avoid leaks or undefined behavior.

Remarks

Closely aligned concepts required to complete one's understanding of (Unsafe) BufferPointers.

  • MemoryLayout (The memory layout of a type, describing its size, stride, and alignment.)
  • Unmanaged (A type for propagating an unmanaged object reference.)
  • UnsafeBufferPointer (A non-owning collection interface to a buffer of elements stored contiguously in memory.)
  • UnsafeBufferPointerIterator (An iterator for the elements in the buffer referenced by an UnsafeBufferPointer or UnsafeMutableBufferPointer instance.)
  • UnsafeMutableBufferPointer (A non-owning collection interface to a buffer of mutable elements stored contiguously in memory.)
  • UnsafeMutablePointer (A pointer for accessing and manipulating data of a specific type.)
  • UnsafeMutableRawBufferPointer (A mutable nonowning collection interface to the bytes in a region of memory.)
  • UnsafeMutableRawBufferPointer.Iterator (An iterator over the bytes viewed by a raw buffer pointer.)
  • UnsafeMutableRawPointer (A raw pointer for accessing and manipulating untyped data.)
  • UnsafePointer (A pointer for accessing data of a specific type.)
  • UnsafeRawBufferPointer (A nonowning collection interface to the bytes in a region of memory.)
  • UnsafeRawBufferPointer.Iterator (An iterator over the bytes viewed by a raw buffer pointer.)
  • UnsafeRawPointer (A raw pointer for accessing untyped data.)

(Source, Swiftdoc.org)