CommunityNews

CommunityNews

The Swift Array Design

Goals

  1. Performance equivalent to C arrays for subscript get/set of non-class element types is the most important performance goal.
  2. It should be possible to receive an NSArray from Cocoa, represent it as an Array<AnyObject>, and pass it right back to Cocoa as an NSArray in O(1) and with no memory allocations.
  3. Arrays should be usable as stacks, so we want amortized O(1) append and O(1) popBack. Together with goal #1, this implies astd::vector-like layout, with a reserved tail memory capacity that can exceed the number of actual stored elements.

To achieve goals 1 and 2 together, we use static knowledge of the element type: when it is statically known that the element type is not a class, code and checks accounting for the possibility of wrapping an NSArray are eliminated. An Array of Swift value types always uses the most efficient possible representation, identical to that of ContiguousArray

https://github.com/apple/swift/blob/main/docs/Arrays.rst

This thread was posted by one of our members via one of our news source trackers.

Where Next?

Popular Macos topics Top

First poster: bot
mikelxc/Workarounds-for-ARM-mac. This repository describes how I get most of my configurations work on the new Apple Silicon Mac - mikel...
New
First poster: bot
How Apple’s rivals plan to catch up with the mighty M1 chip. Apple Silicon is just getting started yet the initial reaction has been rap...
New
First poster: bot
Yesterday, a short Twitter thread by the excellent Jeff Johnson caught my eye. Since he often deletes past tweets, I’ll quote the relevan...
New
First poster: bot
After months of silence about Apple’s impressive M1 chip, Intel just clapped back with a carefully crafted takedown of the Arm-based chip...
New
First poster: bot
Apple has acquired about 100 companies over the last six years, the company’s chief executive Tim Cook has revealed. That works out at a...
New
First poster: bot
Malicious hackers have been exploiting a vulnerability in fully updated versions of macOS that allowed them to take screenshots on infect...
New
First poster: bot
Learn how to use the brand new actor model to protect your application from unwanted data-races and memory issues.
New
First poster: bot
First Look: macOS Monterey Public Beta. If there’s a theme of Apple’s operating-system releases in 2021, it’s platform unification. This...
New
First poster: bot
MainActor is a new attribute introduced in Swift 5.5 as a global actor providing an executor which performs its tasks on the main thread....
New
First poster: bot
I recently received a tantalizing email from a reader I’ve never met: Sam Henri-Gold. Sam showed me how you can key in a couple write co...
New

Other popular topics Top

siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
PragmaticBookshelf
Use WebRTC to build web applications that stream media and data in real time directly from one user to another, all in the browser. ...
New
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
PragmaticBookshelf
Programming Ruby is the most complete book on Ruby, covering both the language itself and the standard library as well as commonly used t...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
PragmaticBookshelf
Fight complexity and reclaim the original spirit of agility by learning to simplify how you develop software. The result: a more humane a...
New
PragmaticBookshelf
A concise guide to MySQL 9 database administration, covering fundamental concepts, techniques, and best practices. Neil Smyth MySQL...
New