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

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:

主站蜘蛛池模板: 张掖市| 香港 | 镶黄旗| 镇远县| 城口县| 驻马店市| 诸暨市| 精河县| 沁阳市| 潼南县| 云霄县| 城步| 盐亭县| 闽侯县| 旬阳县| 封丘县| 体育| 邵武市| 城口县| 巴林右旗| 湖北省| 宁蒗| 七台河市| 措勤县| 满洲里市| 宜宾县| 昭觉县| 永宁县| 平陆县| 庐江县| 大渡口区| 哈巴河县| 盘锦市| 清苑县| 子长县| 广西| 且末县| 北川| 教育| 广西| 康平县|