﻿
{"id":7903,"date":"2018-05-08T12:24:53","date_gmt":"2018-05-08T12:24:53","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=7903"},"modified":"2018-05-08T12:25:03","modified_gmt":"2018-05-08T12:25:03","slug":"c-7-2-readonly-structs","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-7-2-readonly-structs\/","title":{"rendered":"C# 7.2 Readonly Structs"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Yaz\u0131l\u0131m dendi\u011finde \u00e7o\u011fu meslekta\u015f\u0131m\u0131n akl\u0131na &#8220;<em>on binlerce veriyi do\u011fru i\u015fleyebilmek ve bu i\u015flenmi\u015f verileri organize bir \u015fekilde y\u00f6netebilmek<\/em>&#8221; gelmektedir. Lakin ben deniz bu soruya kar\u015f\u0131l\u0131k bu cevab\u0131n her ne kadar do\u011frulu\u011funa kat\u0131lsamda ufak bir n\u00fcans ile t\u00fcm bu s\u00fcreci <em>performans<\/em> odakl\u0131 de\u011ferlendirmekte ve &#8220;<em>on binlerce veriyi do\u011fru i\u015fleyebilmek ve bu i\u015flenmi\u015f verileri organize bir \u015fekilde <strong><em>olabildi\u011fince en y\u00fcksek performansl\u0131<\/em><\/strong> y\u00f6netebilmek<\/em>&#8221; \u015feklinde yorumlamaktay\u0131m.<\/p>\n<p>Bir yaz\u0131l\u0131m\u0131n performans\u0131 y\u00fcksek oranda ilgili yaz\u0131l\u0131m\u0131n \u00fcretiminden sorumlu m\u00fchendis\/uzman\/programc\u0131n\u0131n in\u015fa etti\u011fi kod yap\u0131s\u0131na, yakla\u015f\u0131m\u0131na ve bilgisine ba\u011fl\u0131d\u0131r. Tabi bu oran her ne kadar y\u00fcksek olsada %100 olamayaca\u011f\u0131ndan dolay\u0131 k\u00fc\u00e7\u00fck bir pay\u0131da kullan\u0131lan programlama dili ve mimarisi \u00fcstlenmekte ve o dilin \u00f6zelliklerine ba\u011fl\u0131 olarak de\u011fi\u015fkenlik g\u00f6stermektedir.<\/p>\n<p>Kullan\u0131c\u0131 tarafl\u0131 olan performans s\u00fcre\u00e7leri \u00fczerine onlarca makale yaz\u0131labilir ve yaz\u0131lm\u0131\u015ft\u0131r. Amma velakin kullan\u0131lan dilin performans a\u00e7\u0131s\u0131ndan zay\u0131f olan noktalar\u0131na m\u00fcdahale maksatl\u0131 temas edebilmek o dilin imkanlar\u0131 dahilinde mevcutsa m\u00fcmk\u00fcnd\u00fcr. Yok e\u011fer dil buna m\u00fcsade etmiyorsa eldekiyle yetinilecek ve olabilecek en iyi performans elde edilmeye \u00e7al\u0131\u015f\u0131laca\u011f\u0131ndan dolay\u0131 dilin yap\u0131s\u0131 odakl\u0131 performans de\u011ferlendirmelerini kapsayan i\u00e7erikler pek fazla bulunmamaktad\u0131r.<\/p>\n<p>Bizler ise bu i\u00e7eri\u011fimizde, pek fazla bulunmayan bu kaynaklardan birine el ataca\u011f\u0131z ve bir yandan .NET mimarisinin kendi \u00e7at\u0131s\u0131 alt\u0131ndaki dillere ne kadar d\u00fc\u015f\u00fcnceli yakla\u015ft\u0131\u011f\u0131n\u0131 g\u00f6rece\u011fiz. C# dilinde mikro d\u00fczeyde bir performans\u0131 hesaba katarak geli\u015ftirilmi\u015f olan <strong>readonly structs<\/strong> \u00f6zelli\u011fini de\u011ferlendirecek ve programlama dilini ilgilendiren k\u00fc\u00e7\u00fck bir performansl\u0131k durumun nas\u0131l .NET taraf\u0131ndan dikkate al\u0131n\u0131p \u00f6nlendi\u011fini inceleyece\u011fiz.<\/p>\n<h3>Readonly Structs Nedir?<\/h3>\n<p>C# 7.2 s\u00fcr\u00fcm\u00fc \u00f6ncesi readonly tan\u0131mlanan bir struct de\u011fi\u015fkeninden \u00e7a\u011fr\u0131lan herhangi bir metot neticesinde derleyici ilgili metodun ilgili struct\u0131 de\u011fi\u015ftirip de\u011fi\u015ftirmeyece\u011fi durumunu bilmemesinden kaynakl\u0131 arkaplanda struct\u0131 bir ba\u015fka de\u011fi\u015fkene atamakta ve o de\u011fi\u015fken \u00fczerinden ilgili metodu tetiklemekteydi.<\/p>\n<p>Haliyle <u>programlama dilini ilgilendiren<\/u> bu durum gereksiz bir performans kayb\u0131na yol a\u00e7maktayd\u0131.<\/p>\n<p>C# 7.2 ile birlikte .NET bu durumu d\u00fczeltti ve readonly olarak tan\u0131mlanan struct de\u011fi\u015fkenleri i\u00e7in compiler taraf\u0131ndan arkaplanda olan bu l\u00fczumsuz zahmete son verdi.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nreadonly struct MyStruct\r\n{\r\n    public int X { get; }\r\n    public int Y { get; }\r\n \r\n    public MyStruct(int x, int y)\r\n    {\r\n        X = x;\r\n        Y = y;\r\n    }       \r\n}\r\n<\/pre>\n<p>Bu yap\u0131sal g\u00fcncellemenin pratikte getirisi olan bir de\u011fi\u015fiklik ise readonly olarak tan\u0131mlanan struct i\u00e7erisindeki alanlara sade ve sadece constructer \u00fczerinden de\u011fer atanabilmesi, ba\u015fka bir yerden buna izin verilmemesidir.<\/p>\n<p>\u015eahsen ben .NET mimarisine ve C# diline, mikro d\u00fczeyde olsa bile performans lehine yapm\u0131\u015f oldu\u011fu t\u00fcm yeniliklerden dolay\u0131 sayg\u0131 duymakta ve bununla birlikte gelece\u011fin sayg\u0131n programlama dili olaca\u011f\u0131na kanaat getirmekteyim.<\/p>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar dilerim&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Yaz\u0131l\u0131m dendi\u011finde \u00e7o\u011fu meslekta\u015f\u0131m\u0131n akl\u0131na &#8220;on binlerce veriyi do\u011fru i\u015fleyebilmek ve bu i\u015flenmi\u015f verileri organize bir \u015fekilde y\u00f6netebilmek&#8221; gelmektedir. Lakin ben deniz bu soruya kar\u015f\u0131l\u0131k bu cevab\u0131n her ne kadar do\u011frulu\u011funa kat\u0131lsamda ufak&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":3014,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,2110],"tags":[2112,2305,2337,2336],"class_list":["post-7903","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","category-c-7-2","tag-c-7-2","tag-c-7-2-yenilikleri","tag-c-yenilikleri","tag-readonly-structs"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/7903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=7903"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/7903\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3014"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=7903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=7903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=7903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}