ManagedBuffer

class ManagedBuffer<Header, Element>

A class whose instances contain a property of type Header and raw storage for an array of Element, whose size is determined at instance creation.

Note that the Element array is suitably-aligned raw memory. You are expected to construct and---if necessary---destroy objects there yourself, using the APIs on UnsafeMutablePointer<Element>. Typical usage stores a count and capacity in Header and destroys any live elements in the deinit of a subclass. Note: Subclasses must not have any stored properties; any storage needed should be included in Header.

Import import Swift

Instance Variables

var capacity: Int

The actual number of elements that can be stored in this object.

This header may be nontrivial to compute; it is usually a good idea to store this information in the "header" area when an instance is created.

Declaration

var capacity: Int { get }
var header: Header

The stored Header instance.

During instance creation, in particular during ManagedBuffer.create's call to initialize, ManagedBuffer's header property is as-yet uninitialized, and therefore reading the header property during ManagedBuffer.create is undefined.

Declaration

var header: Header { get set }

Instance Methods

final class func create(_:makingHeaderWith:)

Create a new instance of the most-derived class, calling factory on the partially-constructed object to generate an initial Header.

Declaration

final class func create(minimumCapacity: Int, makingHeaderWith factory: (ManagedBuffer<Header, Element>) throws -> Header) rethrows -> ManagedBuffer<Header, Element>
final func withUnsafeMutablePointerToElements(_:)

Call body with an UnsafeMutablePointer to the Element storage.

Note: This pointer is only valid for the duration of the call to body.

Declaration

final func withUnsafeMutablePointerToElements<R>(_ body: (UnsafeMutablePointer<Element>) throws -> R) rethrows -> R
final func withUnsafeMutablePointerToHeader(_:)

Call body with an UnsafeMutablePointer to the stored Header.

Note: This pointer is only valid for the duration of the call to body.

Declaration

final func withUnsafeMutablePointerToHeader<R>(_ body: (UnsafeMutablePointer<Header>) throws -> R) rethrows -> R
final func withUnsafeMutablePointers(_:)

Call body with UnsafeMutablePointers to the stored Header and raw Element storage.

Note: These pointers are only valid for the duration of the call to body.

Declaration

final func withUnsafeMutablePointers<R>(_ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R) rethrows -> R