Re: [swift-users] How to malloc in Swift 3

2016-09-24 Thread Gerriet M. Denkmann via swift-users
> On 23 Sep 2016, at 19:41, Quinn The Eskimo! via swift-users > wrote: > > > On 23 Sep 2016, at 11:29, Gerriet M. Denkmann via swift-users > wrote: > >> What about calloc then? Or use allocate and do a memset afterwards? > > For trivial data

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Andrew Trick via swift-users
> On Sep 23, 2016, at 2:23 PM, Joe Groff wrote: > > >> On Sep 23, 2016, at 2:20 PM, Jens Persson wrote: >> >> What is the difference between: >> ptr.storeBytes(of: x, toByteOffset: offset, as: type(of: x)) >> ptr.advanced(by:

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Joe Groff via swift-users
> On Sep 23, 2016, at 2:20 PM, Jens Persson wrote: > > What is the difference between: > ptr.storeBytes(of: x, toByteOffset: offset, as: type(of: x)) > ptr.advanced(by: offset).assumingMemoryBound(to: type(of: x)).pointee = x > ? > I noticed that the former traps if storing

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Jens Persson via swift-users
What is the difference between: ptr.storeBytes(of: x, toByteOffset: offset, as: type(of: x)) ptr.advanced(by: offset).assumingMemoryBound(to: type(of: x)).pointee = x ? I noticed that the former traps if storing to a misaligned offset while the latter is happy to do that, and I saw it mentioned as

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Joe Groff via swift-users
> On Sep 23, 2016, at 1:55 AM, Gerriet M. Denkmann via swift-users > wrote: > > >> On 23 Sep 2016, at 15:47, Gerriet M. Denkmann via swift-users >> wrote: >> >> This used to work in Swift 2.2: >> >> var bitfield: UnsafeMutablePointer? >>

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Gerriet M. Denkmann via swift-users
> On 23 Sep 2016, at 15:47, Gerriet M. Denkmann via swift-users > wrote: > > This used to work in Swift 2.2: > > var bitfield: UnsafeMutablePointer? > bitfield = UnsafeMutablePointer( malloc( 888 ) ) > > How is this written in Swift 3.0? To answer my own question:

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Quinn "The Eskimo!" via swift-users
On 23 Sep 2016, at 11:29, Gerriet M. Denkmann via swift-users 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: *

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Gerriet M. Denkmann via swift-users
> On 23 Sep 2016, at 17:08, Svein Halvor Halvorsen via swift-users > wrote: > > var bitfield: UnsafeMutablePointer? > bitfield = UnsafeMutablePointer.allocate(capacity: 888) > Excellent! I see that “- Postcondition: The pointee is allocated, but not initialized.”

Re: [swift-users] How to malloc in Swift 3

2016-09-23 Thread Svein Halvor Halvorsen via swift-users
var bitfield: UnsafeMutablePointer? bitfield = UnsafeMutablePointer.allocate(capacity: 888) > 23. sep. 2016 kl. 10.47 skrev Gerriet M. Denkmann via swift-users > : > > This used to work in Swift 2.2: > > var bitfield: UnsafeMutablePointer? > bitfield =

[swift-users] How to malloc in Swift 3

2016-09-23 Thread Gerriet M. Denkmann via swift-users
This used to work in Swift 2.2: var bitfield: UnsafeMutablePointer? bitfield = UnsafeMutablePointer( malloc( 888 ) ) How is this written in Swift 3.0? Gerriet. ___ swift-users mailing list swift-users@swift.org