Re: [swift-users] Set size of byte array

2016-08-05 Thread KS Sreeram via swift-users
> On 05-Aug-2016, at 4:02 PM, Brent Royal-Gordon wrote: > > I don't believe this is possible with an Array; the only way to work with > uninitialized memory is with an UnsafeMutablePointer. > > The simplest solution is probably to load the data into an allocated chunk of > memory with an Uns

Re: [swift-users] Set size of byte array

2016-08-05 Thread KS Sreeram via swift-users
> On 05-Aug-2016, at 1:19 PM, Daniel Vollmer wrote: > > I’m by no means a Swift expert (not even a user at the moment), but I don't > see a way to do this either. The best that comes to mind is initializing a > ContiguousArray with the sufficient capacity as size, using > withUnsafeBufferPointer

[swift-users] Set size of byte array

2016-08-04 Thread KS Sreeram via swift-users
Hello I’m trying to initialize a byte-array efficiently with minimal copying with the following steps: 1. Create an empty byte array. 2. Reserve sufficient capacity in the array. 3. Use mutable pointers into the array to fill in the data. 4. The actual size that was filled is known only after it

Re: [swift-users] C compatible structs

2016-08-02 Thread KS Sreeram via swift-users
> On 03-Aug-2016, at 10:02 AM, Chris Lattner wrote: > > Right. In the future we will probably add the ability to put explicit > alignment/layout information on structure fields. This would be useful for > this, as well as other cases where you’re trying to match a specific layout > used in a

Re: [swift-users] C compatible structs

2016-08-01 Thread KS Sreeram via swift-users
> On 01-Aug-2016, at 5:17 PM, Chris McIntyre > wrote: > > Swift's strideOf my give you what you want (I'm not at my Mac to test) It doesn’t. Swift uses a different layout than C. In the earlier example code, strideof(Bar) is 8 in Swift, whereas sizeof(Bar) is 12 in C. Best KS Sreeram _

[swift-users] C compatible structs

2016-08-01 Thread KS Sreeram via swift-users
Hello Is it possible to declare Swift structs that have C compatible memory layout? In the code below, Foo and Bar have different sizes in Swift and C. Is it possible to make the Swift structs have the same layout as their C counterparts? // Swift struct Foo { var x: Int32; var a: Int

[swift-users] Memory layout of enums

2016-07-31 Thread KS Sreeram via swift-users
Hi Is there any place I can read about the memory layout of enums with associated values? I’m only interested in POD types. Thanks in advance. Best KS Sreeram ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/

Re: [swift-users] UInt8 in the REPL

2016-07-25 Thread KS Sreeram via swift-users
Thanks all. > On 26-Jul-2016, at 2:46 AM, Chris Lattner wrote: > > >> On Jul 25, 2016, at 2:46 AM, KS Sreeram via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> Hello >> >> In the Swift 2.2 REPL, UInt8(200) is displayed as -

[swift-users] UInt8 in the REPL

2016-07-25 Thread KS Sreeram via swift-users
Hello In the Swift 2.2 REPL, UInt8(200) is displayed as -56. Is this a known problem? “print” works fine though. Best KS Sreeram http://claylabs.com ___ swift-users mailing list swift-users@swift.org https://lists.swift.org/ma