{"id":952,"date":"2009-11-27T23:16:59","date_gmt":"2009-11-27T22:16:59","guid":{"rendered":"http:\/\/soci.hu\/blog\/?p=952"},"modified":"2009-11-28T09:38:10","modified_gmt":"2009-11-28T08:38:10","slug":"naiv-ojjektumhasznalat-sok-szemet","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2009\/11\/27\/naiv-ojjektumhasznalat-sok-szemet\/","title":{"rendered":"Na\u00edv ojjektumhaszn\u00e1lat &#8211; sok szem\u00e9t"},"content":{"rendered":"<p>K\u00e9t hete elkezdtem intenz\u00edven haszn\u00e1lni a Visual Studio 2010-et, mivel sz\u00fcks\u00e9gem volt a MemoryMappedFiles-ra a 4.0-s fwb\u0151l. Ezt shared memoryk\u00e9nt haszn\u00e1lom, amivel a laptopon kb. 1GByte\/sec-kel tudok adatokat m\u00e1solni k\u00e9t processz k\u00f6z\u00f6tt, \u00edgy kiv\u00e1l\u00f3 cache-t tudtam \u00e9p\u00edteni a seg\u00edts\u00e9g\u00e9vel. De most nem err\u0151l lesz sz\u00f3.<br \/>\nA profilert is jelent\u0151sen tov\u00e1bbfejlesztett\u00e9k, van benne pl. rendes mem\u00f3ria allok\u00e1l\u00e1s k\u00f6vet\u00e9s (lehet, hogy a r\u00e9gi is tudta ezt, akkor pardon).<br \/>\nN\u00e9zz\u00fck az al\u00e1bbi k\u00e9pet:<\/p>\n<p><a href=\"http:\/\/soci.hu\/blog\/wp-content\/uploads\/2009\/11\/badmemalloc.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/soci.hu\/blog\/wp-content\/uploads\/2009\/11\/badmemalloc-300x127.png\" alt=\"\" title=\"Felesleges mem\u00f3riafoglal\u00e1sok\" width=\"300\" height=\"127\" class=\"aligncenter size-medium wp-image-953\" srcset=\"https:\/\/soci.hu\/blog\/wp-content\/uploads\/2009\/11\/badmemalloc-300x127.png 300w, https:\/\/soci.hu\/blog\/wp-content\/uploads\/2009\/11\/badmemalloc-600x256.png 600w, https:\/\/soci.hu\/blog\/wp-content\/uploads\/2009\/11\/badmemalloc.png 824w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>A SecondInterval.Day property-t k\u00f6zel 6 milli\u00f3szor h\u00edvtam meg, minden h\u00edv\u00e1skor el\u0151\u00e1ll\u00edtva egy \u00faj ojjektumot, 140MByte-nyi szemetet hagyva magam ut\u00e1n.<\/p>\n<p>A na\u00edv implement\u00e1ci\u00f3 \u00edgy n\u00e9zett ki:<\/p>\n<p>public static SecondInterval Day<br \/>\n{<br \/>\n  get { return new SecondInterval(86400); }<br \/>\n}<\/p>\n<p>Maga a t\u00edpus egy egyszer\u0171 <a href=\"http:\/\/fit.c2.com\/wiki.cgi?WholeValue\">Whole Value pattern<\/a> implement\u00e1ci\u00f3, egy sima immutable objektum, r\u00e1ad\u00e1sul class, \u00edgy referenci\u00e1lis t\u00edpus.<\/p>\n<p>Nem mem\u00f3riapazarl\u00f3 m\u00f3don \u00edgy n\u00e9z ki a property:<\/p>\n<p>private static readonly SecondInterval aDay = new SecondInterval(86400);<br \/>\npublic static SecondInterval Day<br \/>\n{<br \/>\n    get { return aDay ; }<br \/>\n}<\/p>\n<p>A readonly fontos, hogy nehogy valaki ki\u00fcsse a referenci\u00e1mat, \u00e9s berakjon egy sunyi m\u00e1sik id\u0151t reprezent\u00e1l\u00f3 ojjektumot a napi hely\u00e9re. Az ojjektum immutable, ez fontos, m\u00e1sk\u00e9nt semmit nem \u00e9rne a readonly, a gyomr\u00e1t lehetne piszk\u00e1lgatni.<br \/>\nAmin m\u00e9g el lehetne gondolkodni, hogy strukt\u00far\u00e1v\u00e1, value type-p\u00e1 \u00e1talak\u00edtani a t\u00edpust, csak akkor meg minden helyen ahol haszn\u00e1lom, m\u00e1solni kellene az \u00e9rt\u00e9k\u00e9t. Mivel ez most bel\u00fcl egy 32 bites int, \u00e9s 64 bit alatt futtatom, ahol a referenci\u00e1k 64 bitesek, a m\u00e1sol\u00e1ssal m\u00e9g mindig jobban j\u00e1rok. \u00dagyhogy lehet, hogy struct lesz, de el\u0151bb megn\u00e9zem classk\u00e9nt hogy muzsuik\u00e1l.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>K\u00e9t hete elkezdtem intenz\u00edven haszn\u00e1lni a Visual Studio 2010-et, mivel sz\u00fcks\u00e9gem volt a MemoryMappedFiles-ra a 4.0-s fwb\u0151l. Ezt shared memoryk\u00e9nt haszn\u00e1lom, amivel&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,10,11,4],"tags":[],"class_list":["post-952","post","type-post","status-publish","format-standard","hentry","category-net","category-c","category-clr","category-szakmai-elet"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=952"}],"version-history":[{"count":3,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/952\/revisions"}],"predecessor-version":[{"id":955,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/952\/revisions\/955"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}