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 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]
