memmove in Swift
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