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.

Popular Mac Os topics Top

AstonJ
We all knew it was coming… What do you think? Apple has confirmed it will transition its Mac laptop and desktop computers to its own A...
New
MikhailPertsev
Hi there! I am a new iMac user (this is the first Apple’s product for me), and I am wondering should I update the mac OS system to the n...
New
siddhant3030
I have a new MacBook Pro which I’m connecting to an external monitor. I know why it is heating but I want to know if anyone having the sa...
New
MikhailPertsev
Hi there! I wonder what is better for performance and “longevity” for iMac: should it be turned off through “Shut down” or should I put ...
New
CommunityNews
Over the past decade, a large and opaque industry has been amassing increasing amounts of personal data.1,2 A complex ecosystem of websi...
New
First poster: kokolegorille
hello (also known as helloSystem ) is a desktop system for creators with focus on simplicity, elegance, and usability. Its design follows...
New
First poster: AstonJ
Vitals is a little Mac app I built recently that shows you which programs are slowing your computer down. It lives in the menu bar, keepi...
New
abhimohata
I am intending to show an alert message in macOS through a C++ based application. I am using CFUserNotificationDisplayAlert for the same....
New
d1bg12
Hello, Apple developers! I want to upload an app to testflight, but I’m having the issue from the picture and I can’t get around it. Ha...
New
AstonJ
Just looking through my settings and noticed that Help Apple Improve Search was checked - yet I am almost certain that I did not opt-in t...
New

Other popular topics Top

malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
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
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New