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.

First Post!

bot

bot

Corresponding tweet for this thread:

Share link for this tweet.

Popular Macos topics Top

First poster: bot
Really, really add /usr/local/bin to the PATH variable on macOS. In newer macOS custom executables belong in a directory which is not in...
New
First poster: bot
We’ll guide you through the process of using Homebrew package manager to install security tools on macOS to exploit vulnerabilities found...
New
First poster: bot
The Mac has always been very different from its close relative, iOS, especially when it comes to what a user is or is not allowed to run ...
New
First poster: bot
Fed up with the Mac, I spent six months with a Linux laptop. The grass is not greener on the other side April 02, 2021 — Carlos Fenollosa...
New
First poster: bot
Doing high-performance 3D rendering on the Web has always been a tricky proposition. WebGL, in its quest for programmer familiarity and ...
New
First poster: bot
Swift 5.5 is here with Xcode 13 Beta and with it comes my favorite new addition to Swift: Async/Await. Async/await is a high level, stru...
New
First poster: bot
The ARM architecture defines rules for how to call functions, manage the stack, and perform other operations. If part of your code includ...
New
First poster: bot
Apple Makes OS X Lion and Mountain Lion Free to Download. Apple recently dropped the $19.99 fee for OS X Lion and Mountain Lion, making ...
New
First poster: bot
TLDR; I realised that my life while using Apple products is controlled by Product Managers/Owners who want to get a raise, rather than ...
New
First poster: bot
Recommended settings for Wi-Fi routers and access points. For the best security, performance, and reliability, we recommend these settin...
New

Other popular topics Top

DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
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
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
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
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
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New

Latest in Blogs/Talks

View all threads ❯