• 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: Quincey Morris <email@hidden>
  • Date: Wed, 20 Aug 2014 21:25:44 -0700

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)

— 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.

_______________________________________________

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


  • Follow-Ups:
    • Re: memmove in Swift
      • From: Roland King <email@hidden>
    • Re: memmove in Swift
      • From: "Gerriet M. Denkmann" <email@hidden>
    • Re: memmove in Swift
      • From: Kyle Sluder <email@hidden>
References: 
 >memmove in Swift (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: How can an instance KVO its own and super's attributes, especially with overrides?
  • Next by Date: Re: How can an instance KVO its own and super's attributes, especially with overrides?
  • Previous by thread: memmove in Swift
  • Next by thread: Re: memmove in Swift
  • Index(es):
    • Date
    • Thread