ManagedBufferPointer
Contains a buffer object, and provides access to an instance of Header
and contiguous storage for an arbitrary number of Element
instances stored in that buffer.
@frozen struct ManagedBufferPointer<Header, Element>
For most purposes, the ManagedBuffer
class can be used on its own. However, in cases where objects of various different classes must serve as storage, you need to also use ManagedBufferPointer
.
A valid buffer class is non-@objc
, with no declared stored properties. Its deinit
must destroy its stored Header
and any constructed Element
s.
Example Buffer Class
class MyBuffer<Element> { // non-@objc
typealias Manager = ManagedBufferPointer<(Int, String), Element>
deinit {
Manager(unsafeBufferObject: self).withUnsafeMutablePointers {
(pointerToHeader, pointerToElements) -> Void in
pointerToElements.deinitialize(count: self.count)
pointerToHeader.deinitialize(count: 1)
}
}
// All properties are *computed* based on members of the Header
var count: Int {
return Manager(unsafeBufferObject: self).header.0
}
var name: String {
return Manager(unsafeBufferObject: self).header.1
}
}
Citizens in Swift
Conformances
protocol Equatable
A type that can be compared for value equality.
protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.
Members
init(bufferClass: AnyClass, minimumCapacity: Int, makingHeaderWith: (AnyObject, (AnyObject) -> Int) throws -> Header
) rethrows Create with new storage containing an initial
Header
and space for at leastminimumCapacity
element
s.init(unsafeBufferObject: AnyObject
) Manage the given
buffer
.var buffer: AnyObject
Returns the object instance being used for storage.
var capacity: Int
The actual number of elements that can be stored in this object.
var header: Header
The stored
Header
instance.static func == (ManagedBufferPointer
<Header, Element>, ManagedBufferPointer<Header, Element>) -> Bool func isUniqueReference(
) -> Bool Returns
true
ifself
holds the only strong reference to its buffer; otherwise, returnsfalse
.func withUnsafeMutablePointerToElements<R>((UnsafeMutablePointer<Element>) throws -> R
) rethrows -> R Call
body
with anUnsafeMutablePointer
to theElement
storage.func withUnsafeMutablePointerToHeader<R>((UnsafeMutablePointer<Header>) throws -> R
) rethrows -> R Call
body
with anUnsafeMutablePointer
to the storedHeader
.func withUnsafeMutablePointers<R>((UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R
) rethrows -> R Call
body
withUnsafeMutablePointer
s to the storedHeader
and rawElement
storage.