- Reactive Programming with Swift 4
- Navdeep Singh
- 127字
- 2021-06-24 18:57:58
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:

推薦閱讀
- Getting Started with React
- Raspberry Pi for Secret Agents(Third Edition)
- Getting Started with CreateJS
- 數(shù)據(jù)結(jié)構(gòu)(Python語言描述)(第2版)
- VMware vSphere 6.7虛擬化架構(gòu)實戰(zhàn)指南
- Learning OpenStack Networking(Neutron)
- MATLAB for Machine Learning
- Python之光:Python編程入門與實戰(zhàn)
- Creating Stunning Dashboards with QlikView
- HoloLens與混合現(xiàn)實開發(fā)
- UI設(shè)計全書(全彩)
- Machine Learning With Go
- C語言程序設(shè)計實訓(xùn)教程與水平考試指導(dǎo)
- 硬件產(chǎn)品設(shè)計與開發(fā):從原型到交付
- Scrapy網(wǎng)絡(luò)爬蟲實戰(zhàn)