[swift-users] How to malloc in Swift 3

Gerriet M. Denkmann g at mdenkmann.de
Fri Sep 23 05:29:54 CDT 2016


> On 23 Sep 2016, at 17:08, Svein Halvor Halvorsen via swift-users <swift-users at swift.org> wrote:
> 
> var bitfield: UnsafeMutablePointer<UInt8>?
> bitfield = UnsafeMutablePointer<UInt8>.allocate(capacity: 888)
> 

Excellent! 
I see that “- Postcondition: The pointee is allocated, but not initialized.”

What about calloc then? Or use allocate and do a memset afterwards?

Thanks a lot for your help!

Kind regards,

Gerriet.



>> 23. sep. 2016 kl. 10.47 skrev Gerriet M. Denkmann via swift-users <swift-users at swift.org>:
>> 
>> This used to work in Swift 2.2:
>> 
>> var bitfield: UnsafeMutablePointer<UInt8>?
>> bitfield = UnsafeMutablePointer<UInt8>( malloc( 888 ) )
>> 
>> How is this written in Swift 3.0?
>> 
>> Gerriet.
>> 
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list