ManagedBuffer

class ManagedBuffer

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.

Instance Variables

var capacity Required

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
var header Required

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

Instance Methods

func create(minimumCapacity: Int, makingHeaderWith factory: (ManagedBuffer<Header, Element>) throws -> Header) rethrows -> ManagedBuffer<Header, Element> Required

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

Declaration

@inlinable final public class func create(minimumCapacity: Int, makingHeaderWith factory: (ManagedBuffer<Header, Element>) throws -> Header) rethrows -> ManagedBuffer<Header, Element>
func withUnsafeMutablePointerToElements(_ body: (UnsafeMutablePointer<Element>) throws -> R) rethrows -> R Required

Call body with an UnsafeMutablePointer to the Element storage.

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

Declaration

@inlinable final public func withUnsafeMutablePointerToElements<R>(_ body: (UnsafeMutablePointer<Element>) throws -> R) rethrows -> R
func withUnsafeMutablePointerToHeader(_ body: (UnsafeMutablePointer<Header>) throws -> R) rethrows -> R Required

Call body with an UnsafeMutablePointer to the stored Header.

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

Declaration

@inlinable final public func withUnsafeMutablePointerToHeader<R>(_ body: (UnsafeMutablePointer<Header>) throws -> R) rethrows -> R
func withUnsafeMutablePointers(_ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R) rethrows -> R Required

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

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

Declaration

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