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

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:

主站蜘蛛池模板: 渝北区| 镇康县| 陈巴尔虎旗| 江油市| 门源| 东阳市| 于都县| 凤凰县| 沾益县| 同德县| 呼伦贝尔市| 富平县| 宣威市| 晋宁县| 乌拉特后旗| 满洲里市| 洛川县| 利辛县| 饶河县| 怀仁县| 日喀则市| 罗田县| 义乌市| 耿马| 平舆县| 石楼县| 金坛市| 驻马店市| 绿春县| 文昌市| 石河子市| 宣恩县| 叙永县| 油尖旺区| 陈巴尔虎旗| 彭州市| 商南县| 翁牛特旗| 安陆市| 随州市| 鱼台县|