struct
ManagedBufferPointer
<
Header
,
Element
>
Inheritance |
Equatable
View Protocol Hierarchy →
|
---|---|
Import |
|
Initializers
Create with new storage containing an initial Header
and space
for at least minimumCapacity
element
s.
bufferClass
: The class of the object used for storage.
minimumCapacity
: The minimum number of Element
s that
must be able to be stored in the new buffer.
factory
: A function that produces the initial
Header
instance stored in the buffer, given the buffer
object and a function that can be called on it to get the actual
number of allocated elements.
Precondition: minimumCapacity >= 0
, and the type indicated by
bufferClass
is a non-@objc
class with no declared stored
properties. The deinit
of bufferClass
must destroy its
stored Header
and any constructed Element
s.
Declaration
Manage the given buffer
.
Precondition: buffer
is an instance of a non-@objc
class whose
deinit
destroys its stored Header
and any constructed Element
s.
Declaration
init
(
unsafeBufferObject
buffer
:
AnyObject
)
Instance Variables
The actual number of elements that can be stored in this object.
This value 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.
Declaration
var
header
:
Header
{
get
set
}
Instance Methods
Returns true
iff self
holds the only strong reference to its buffer.
See isUniquelyReferenced
for details.
Declaration
mutating
func
isUniqueReference
() -
>
Bool
Call body
with an UnsafeMutablePointer
to the Element
storage.
Note: This pointer is only valid for the duration of the
call to body
.
Declaration
func
withUnsafeMutablePointerToElements
<
R
>
(
_
body
: (
UnsafeMutablePointer
<
Element
>
)
throws
-
>
R
)
rethrows
-
>
R
Call body
with an UnsafeMutablePointer
to the stored
Header
.
Note: This pointer is only valid
for the duration of the call to body
.
Declaration
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 only valid for the duration of the
call to body
.
Declaration
func
withUnsafeMutablePointers
<
R
>
(
_
body
: (
UnsafeMutablePointer
<
Header
>
,
UnsafeMutablePointer
<
Element
>
)
throws
-
>
R
)
rethrows
-
>
R
Contains a buffer object, and provides access to an instance of
Header
and contiguous storage for an arbitrary number ofElement
instances stored in that buffer.For most purposes, the
ManagedBuffer
class works fine for this purpose, and can simply be used on its own. However, in cases where objects of various different classes must serve as storage,ManagedBufferPointer
is needed.A valid buffer class is non-
@objc
, with no declared stored properties. Itsdeinit
must destroy its storedHeader
and any constructedElement
s.Example Buffer Class