init(rawCapacity:initializingWith:)
Creates a data instance with the specified capacity, and then calls the given closure with an output span covering the instance’s uninitialized memory.
Declaration
init<E>(rawCapacity capacity: Int, initializingWith initializer: @_lifetime(span: copy span) (inout OutputRawSpan) throws(E) -> Void) throws(E) where E : ErrorParameters
- capacity:
The number of bytes to allocate space for in the new
Data. - initializer:
A closure to initialize the allocated memory.
Parameters:
span: An
OutputRawSpancovering uninitialized memory with space for the specified number of bytes.
Discussion
Inside the closure, initialize elements by appending to the OutputRawSpan. The OutputRawSpan keeps track of the initialized memory, ensuring safety. Its count at the end of the closure will become the count of the newly-initialized instance of Data.