官术网_书友最值得收藏!

Reserving capacity

Dictionary and sequence now have the capacity to explicitly, unambiguously reserve capacity.

Suppose you have a sequence of friends with an initial capacity of 4:

friends.capacity  // 4

You can now reserve the capacity by doing this:

friends.reserveCapacity(20)

This reserves a minimum of 20 segments of capacity:

friends.capacity // 20

Reallocating memory to objects can be an expensive task, and if you have an idea about how much space it will require to store an object, then using reserveCapacity(_:) can be an easy and simple way to increase performance.

Swift 4 brings in a number of modifications to the Dictionary, 12 to be exact as per the official Apple developers guide, and a number of additions that we will discuss in subsequent sections:

主站蜘蛛池模板: 黎川县| 高清| 清水河县| 息烽县| 剑河县| 太白县| 蚌埠市| 介休市| 龙山县| 肇源县| 库车县| 虹口区| 祁东县| 三原县| 石林| 仙居县| 揭阳市| 什邡市| 名山县| 三都| 铁岭县| 嫩江县| 泸溪县| 郯城县| 乐安县| 文安县| 乌什县| 惠来县| 株洲市| 穆棱市| 会东县| 十堰市| 盘锦市| 景德镇市| 长寿区| 巨鹿县| 南澳县| 靖州| 青阳县| 甘洛县| 喜德县|