• 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
memmove in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

memmove in Swift


  • Subject: memmove in Swift
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Thu, 21 Aug 2014 10:32:03 +0700

This works:

private func shiftArray( inout arr: [UInt32], lowerIndex: UInt, upperIndex: UInt )
{
	//	move: arr[ lowerIndex ..< upperIndex ] to: arr[ lowerIndex + 1 ... upperIndex ]

	let av = arr[ Int(upperIndex) ]

	for var i = upperIndex - 1;; i--
	{
		arr[ Int(i+1) ] = arr[ Int(i) ]
		if i == lowerIndex { break }
	}

	arr[ Int(lowerIndex) ] = av
}

But I thought that maybe memmove might be more efficient:

let dest : UnsafeMutablePointer<Void> =  arr + lowerIndex + 1
let orig : UnsafePointer<Void> =  arr + lowerIndex
let nbrInts = upperIndex - 1 - lowerIndex
let nbrBytes = nbrInts * UInt( sizeof(UInt32) )
memmove( dest, orig, nbrBytes )

But I can't get my Unsafe Pointers to compile.
Tried everything I could think of. But got only varying (not very helpful) error messages.

Is this possible in Swift?

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


  • Follow-Ups:
    • Re: memmove in Swift
      • From: Marco S Hyman <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: How can an instance KVO its own and super's attributes, especially with overrides?
  • Previous by thread: Re: Good way to have default relationship to override nil?
  • Next by thread: Re: memmove in Swift
  • Index(es):
    • Date
    • Thread