{"id":13481,"date":"2016-02-11T12:04:02","date_gmt":"2016-02-11T17:04:02","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=13481"},"modified":"2016-02-11T12:04:02","modified_gmt":"2016-02-11T17:04:02","slug":"swift-struct-storage","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/02\/11\/swift-struct-storage\/","title":{"rendered":"Swift Struct Storage"},"content":{"rendered":"<p><a href=\"https:\/\/www.mikeash.com\/pyblog\/friday-qa-2016-01-29-swift-struct-storage.html\">Mike Ash<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.mikeash.com\/pyblog\/friday-qa-2016-01-29-swift-struct-storage.html\">\n<p>We can see that it&rsquo;s exactly as we expected: when passing the <code>struct<\/code> to an <code>inout<\/code> parameter, the <code>struct<\/code> is laid out contiguously in memory and then a pointer to it is passed in.<\/p>\n<p>[&#8230;]<\/p>\n<p><code>struct<\/code> storage in Swift is ultimately pretty straightforward, and much of what we&rsquo;ve seen carries over from C&rsquo;s much simpler <code>struct<\/code>s. A <code>struct<\/code> instance is largely treated as a loose collection of independent values, which can be manipulated collectively when required. Local <code>struct<\/code> variables might be stored on the stack or the individual pieces might be stored in registers, depending on the size of the <code>struct<\/code>, the register usage of the rest of the code, and the whims of the compiler. Small <code>struct<\/code>s are passed and returned in registers, while larger <code>struct<\/code>s are passed and returned by reference. <code>struct<\/code>s get copied whenever they&rsquo;re passed and returned. Although you can use <code>struct<\/code>s to implement copy-on-write data types, the base language construct is copied eagerly and more or less blindly.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Mike Ash: We can see that it&rsquo;s exactly as we expected: when passing the struct to an inout parameter, the struct is laid out contiguously in memory and then a pointer to it is passed in. [&#8230;] struct storage in Swift is ultimately pretty straightforward, and much of what we&rsquo;ve seen carries over from C&rsquo;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[46,138,71,901,943],"class_list":["post-13481","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-languagedesign","tag-optimization","tag-programming","tag-swift-programming-language","tag-swift-runtime"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=13481"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13481\/revisions"}],"predecessor-version":[{"id":13482,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/13481\/revisions\/13482"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=13481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=13481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=13481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}