[swift-users] How to malloc in Swift 3
Gerriet M. Denkmann
gerrietm at me.com
Fri Sep 23 03:55:17 CDT 2016
> On 23 Sep 2016, at 15:47, Gerriet M. Denkmann via swift-users <swift-users at swift.org> wrote:
> 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?
To answer my own question:
var bitfield: UnsafeMutableRawPointer
bitfield = UnsafeMutableRawPointer( malloc(888))
But then this stops working:
let theByte = self.bitfield[ 5 ]
Somehow the bitfield must know that it is a field of bytes (not shorts, ints or whatever). But how?
More information about the swift-users