- 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:

推薦閱讀
- Visual Basic .NET程序設計(第3版)
- LabVIEW 2018 虛擬儀器程序設計
- Python自然語言處理實戰:核心技術與算法
- Learning Real-time Processing with Spark Streaming
- C語言程序設計習題解析與上機指導(第4版)
- Vue.js快速入門與深入實戰
- Building Mapping Applications with QGIS
- PostgreSQL Replication(Second Edition)
- Learning Python Design Patterns
- Linux Device Drivers Development
- Node學習指南(第2版)
- Spring技術內幕:深入解析Spring架構與設計原理(第2版)
- Hands-On Kubernetes on Windows
- 新印象:解構UI界面設計
- Webpack實戰:入門、進階與調優(第2版)