Array with capacity in Swift -
how initialise array maximum capacity without repeatedvalues?
var anotherthreedoubles = array(count: 3, repeatedvalue: 2.5) like in illustration repeatedvalue.can initialise without value ?
cmd-clicking array type in xcode finds me next function definition (along doc comment):
/// ensure array has plenty mutable contiguous storage store /// minimumcapacity elements in. note: not impact count. /// complexity: o(n) mutating func reservecapacity(minimumcapacity: int) so in way, you can tell array pre-allocate storage given capacity doing this:
var results: [t] = [] results.reservecapacity(100) and theoretically, hundred appends on array should performs improve without capacity reservation call.
to enforce "maximum" capacity though, there no way short of custom code manually putting nils array of optional<t>s capped maximum size suggested @bryan in question comments.
swift
No comments:
Post a Comment