• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: memmove in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memmove in Swift


  • Subject: Re: memmove in Swift
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Thu, 21 Aug 2014 11:54:35 +0700

On 21 Aug 2014, at 11:25, Quincey Morris <email@hidden> wrote:

> On Aug 20, 2014, at 20:32 , Gerriet M. Denkmann <email@hidden> 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@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


References: 
 >memmove in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: memmove in Swift (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: memmove in Swift
  • Next by Date: Re: memmove in Swift
  • Previous by thread: Re: memmove in Swift
  • Next by thread: Re: memmove in Swift
  • Index(es):
    • Date
    • Thread