<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">As far as I know, the only guarantee is made for structures imported from C. From&nbsp;<a href="https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001968.html" class="">https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001968.html</a>&nbsp;:<div class=""><br class=""></div><div class="">&nbsp; &nbsp;Swift structs have unspecified layout. If you depend on a specific layout, you should define the struct in C and import it into Swift for now.</div><br class="Apple-interchange-newline">and from&nbsp;<a href="https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001980.html" class="">https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160516/001980.html</a>&nbsp;:<div class=""><br class=""></div><div class="">&nbsp; &nbsp;That's not necessary. You can leave the struct defined in C and import it into Swift. Swift will respect C's layout.<br class=""><br class="Apple-interchange-newline">Regards, Martin</div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 28. Apr 2017, at 13:03, Johannes Weiss via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi swift-users,<br class=""><br class="">(sorry for the cross post to swift-dev, but wasn't sure where it belongs)<br class=""><br class="">I tried to find guarantees about the memory layout Swift tuples but couldn't find anything. The reason I ask is because I'd like to use them as fixed sized (stack allocated) arrays. I'm pretty sure they're actually not guaranteed to be stack allocated but highly likely I assume :).<br class=""><br class="">Am I correct in assuming that<br class=""><br class=""> &nbsp;&nbsp;&nbsp;let swift_events: (kevent, kevent) = ...<br class=""><br class="">has the same memory layout as<br class=""><br class=""> &nbsp;&nbsp;&nbsp;struct kevent c_events[2] = ...<br class=""><br class="">? In other words, is this legal:<br class=""><br class=""> &nbsp;&nbsp;&nbsp;var events = (kevent(), kevent())<br class=""> &nbsp;&nbsp;&nbsp;withUnsafeMutableBytes(of: &amp;events) { event_ptr in<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;precondition(MemoryLayout&lt;kevent&gt;.size * 2 == event_ptr.count)<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if let ptr = event_ptr.baseAddress?.bindMemory(to: kevent.self, capacity: 2) {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return kevent(someFileDescriptor, ptr, 2, ptr, 2, nil)<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class="">I'm assuming yes but I'd like to make sure.<br class=""><br class="">Many thanks,<br class=""> &nbsp;Johannes<br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>