On 21 Aug 2014, at 11:25, Quincey Morris <[email protected]> 
wrote:

> On Aug 20, 2014, at 20:32 , Gerriet M. Denkmann <[email protected]> wrote:
> 
>> But I thought that maybe memmove might be more efficient:
>> 
>> let dest : UnsafeMutablePointer<Void> =  arr + lowerIndex + 1
> 
> Er, no. There are multiple things wrong with this:
> 
> — There’s nothing in the Swift array API contract that says that elements are 
> stored in a contiguous block of memory, or even in several blocks of memory

> — Even if they were, there’s nothing that says how they’re laid out in that 
> memory
> 
> — Even if there was, there’s nothing that gives you access to that memory 
> (well, AFAIK)

Earlier version of Swift indeed had some funny way to lay out arrays.
But in the official Swift blog (29/07/2014) there is this example:

import Accelerate

let a: [Float] = [1, 2, 3, 4]
let b: [Float] = [0.5, 0.25, 0.125, 0.0625]
var result: [Float] = [0, 0, 0, 0]
vDSP_vadd(a, 1, b, 1, &result, 1, 4)
// result now contains [1.5, 2.25, 3.125, 4.0625]

which seems to imply that arrays now are layed out in a natural way.

> — Even if there was, the use of ‘arr’ as a pointer to the start of the memory 
> is a C-ism, and doesn’t apply to an array variable in Swift.
> 
> If you want to do this sort of thing, you’re going to have to cause your own 
> block of memory to be allocated (e.g. in a NSData object). Alternatively, you 
> could code the move as you originally did, and trust that at some point the 
> Swift compiler will understand what you’re doing and optimize it for you.

Ok. That is what I am doing.

Thanks!


Kind regards,

Gerriet.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to