Re: Swift and Threads
Re: Swift and Threads
- Subject: Re: Swift and Threads
- From: Quincey Morris <email@hidden>
- Date: Mon, 12 Sep 2016 11:11:53 -0700
- Feedback-id: 167118m:167118agrif8a:167118sE7JjjSVJy:SMTPCORP
On Sep 12, 2016, at 10:16 , Jens Alfke <email@hidden> wrote:
>
> The question in my mind is whether the array struct ever gets copied in this code — it’s not explicitly passed as a parameter, just closed over. I don’t think I’ve read any docs that describe explicitly what the behavior is, maybe because it only becomes significant when you introduce threads?
The array is going to get copied at least once, because it’s a local variable captured by a block. That means it needs to be copied to the heap.
> This situation also begs the question of what kind of lower-level data structure one can use in Swift when Array is too high-level. In Obj-C one can drop down to C arrays, for example.
My understanding is that pure Swift arrays (that is, *not* bridged NSArrays) are stored as efficiently as C arrays.
However, in this particular example, the array, a mutable structure, is modified unsafely from multiple threads. That may or may not be the cause of the crash, but it’s certainly a bug that should be fixed first.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden