class ManagedBuffer<Header, Element>
Import | import Swift |
---|
Instance Variables
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 }
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
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>
Call body
with an UnsafeMutablePointer
to the Element
storage.
Note: This pointer is valid only for the duration of the
call to body
.
Declaration
final func withUnsafeMutablePointerToElements<R>(_ body: (UnsafeMutablePointer<Element>) throws -> R) rethrows -> R
Call body
with an UnsafeMutablePointer
to the stored
Header
.
Note: This pointer is valid only for the duration of the
call to body
.
Declaration
final func withUnsafeMutablePointerToHeader<R>(_ body: (UnsafeMutablePointer<Header>) throws -> R) rethrows -> R
Call body
with UnsafeMutablePointer
s to the stored Header
and raw Element
storage.
Note: These pointers are valid only for the duration of the
call to body
.
Declaration
final func withUnsafeMutablePointers<R>(_ body: (UnsafeMutablePointer<Header>, UnsafeMutablePointer<Element>) throws -> R) rethrows -> R
A class whose instances contain a property of type
Header
and raw storage for an array ofElement
, 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 onUnsafeMutablePointer<Element>
. Typical usage stores a count and capacity inHeader
and destroys any live elements in thedeinit
of a subclass. Note: Subclasses must not have any stored properties; any storage needed should be included inHeader
.