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

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:

主站蜘蛛池模板: 五原县| 齐齐哈尔市| 石景山区| 东乌珠穆沁旗| 淳化县| 诏安县| 缙云县| 历史| 招远市| 长岛县| 玛多县| 东丽区| 湖州市| 安仁县| 安龙县| 防城港市| 崇义县| 沽源县| 丁青县| 营口市| 澜沧| 普格县| 广河县| 诏安县| 霍林郭勒市| 仲巴县| 西和县| 北碚区| 舟山市| 通城县| 峡江县| 同江市| 综艺| 石门县| 乌兰浩特市| 弋阳县| 遂宁市| 临沭县| 赣榆县| 察雅县| 鄂伦春自治旗|