• 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: Kyle Sluder <email@hidden>
  • Date: Wed, 20 Aug 2014 23:52:44 -0500

On Wed, Aug 20, 2014, at 11:25 PM, Quincey Morris wrote:
> — 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)

See Array.withUnsafeBufferPointer(), which is commented to invoke its
closure with "a pointer to the Array's contiguous storage".

Also see this post from an Apple engineer in the Dev Forums.
Single-dimensional Swift arrays can be passed directly to C APIs,
meaning their internal layout is almost certainly identical. (Though I
can find no such guarantee in the documentation, anything else would
imply the potential of an expensive copy when calling a C API.)
<https://devforums.apple.com/message/1017401#1017401>

Also see this post that clearly warns that multidimensional Swift arrays
are NOT laid out like multidimensional C arrays:
<https://devforums.apple.com/message/1015588#1015588>

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

Correct. This is what withUnsafe{,Buffer}Pointer() is for.

--Kyle Sluder

_______________________________________________

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: Good way to have default relationship to override nil?
  • 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