[swift-users] How to malloc in Swift 3
Quinn "The Eskimo!"
eskimo1 at apple.com
Fri Sep 23 07:41:42 CDT 2016
On 23 Sep 2016, at 11:29, Gerriet M. Denkmann via swift-users <swift-users at swift.org> wrote:
> What about calloc then? Or use allocate and do a memset afterwards?
For trivial data types (like UInt8) this will work, but if you want to follow the rules I recommend reading the following:
* UnsafeRawPointer Migration
<https://swift.org/migration-guide/se-0107-migrate.html>
* SE-0107 “UnsafeRawPointer API”
<https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md>
Spoiler: that’ll point you to `initialize(to:count:)` (-:
* * *
Also, why are you manually allocating this rather than using [UInt8]? The latter is easier, safer, and likely to have similar levels of efficiency.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
More information about the swift-users
mailing list