{"id":3402,"date":"2018-07-09T11:52:45","date_gmt":"2018-07-09T02:52:45","guid":{"rendered":"http:\/\/soundengine.jp\/wordpress\/tips\/?p=3402"},"modified":"2018-07-09T12:11:09","modified_gmt":"2018-07-09T03:11:09","slug":"memorymappedfile%e3%81%a7%e6%a7%8b%e9%80%a0%e4%bd%93%e3%81%ae%e8%aa%ad%e3%81%bf%e6%9b%b8%e3%81%8d","status":"publish","type":"post","link":"https:\/\/soundengine.jp\/wordpress\/tips\/try\/3402\/","title":{"rendered":"MemoryMappedFile\u3067\u69cb\u9020\u4f53\u306e\u8aad\u307f\u66f8\u304d"},"content":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u306a\u3093\u3067\u3082\u51e6\u7406\u3059\u308b\u3068\u3044\u3046\u306e\u306f\u6700\u8fd1\u306e\u30c8\u30ec\u30f3\u30c9\u306a\u306e\u304b\u3082\u3057\u308c\u306a\u3044\u3051\u3069\u3001\u3042\u308b\u5834\u5408\u306b\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u30d9\u30fc\u30b9\u3067\u5168\u7136\u9593\u306b\u5408\u3046\u3093\u3058\u3083\u306a\u3044\u304b\uff1f\u3068\u304b\u30d5\u30a1\u30a4\u30eb\u30d9\u30fc\u30b9\u306e\u65b9\u304c\u901f\u3044\u3093\u3058\u3083\u306a\u3044\u304b\uff1f\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306fMemoryMappedFile\u3067\u69cb\u9020\u4f53\u3092\u8aad\u307f\u8fbc\u3080\u3068\u3044\u3046\u306e\u3092\u3084\u3063\u3066\u307f\u305f\u3002<\/p>\n<p>\uff08C#\u3067\u69cb\u9020\u4f53\u8aad\u307f\u8fbc\u307f\u306a\u3093\u3066\u3042\u307e\u308a\u3084\u3089\u306a\u3044\u3053\u3068\u306a\u306e\u304b\u3082\u3057\u308c\u306a\u3044\u3051\u3069\uff09<br \/>\n<!--more--><\/p>\n<p>\u3072\u3068\u307e\u305a\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u3063\u305f\u3002<\/p>\n<p>\u69cb\u9020\u4f53History\u3092\u5b9a\u7fa9\u3057\u3066\u3001MemoryMappedFile.CreateFromFile\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3002CreateViewAccessor\u3067\u30e9\u30f3\u30c0\u30e0 \u30a2\u30af\u30bb\u30b9 \u30d3\u30e5\u30fc\u3092\u4f5c\u6210\u3057\u3066\u3001\u69cb\u9020\u4f53\u3092\u66f8\u304d\u8fbc\u307f\u30fb\u8aad\u307f\u8fbc\u307f\u3059\u308b\u6d41\u308c\u3002<\/p>\n<pre class=\"lang:c# decode:true \">{\r\nstruct History\r\n{\r\n\tpublic long FileTime;\r\n\tpublic long Price;\r\n\tpublic long Amount;\r\n}\r\n\r\nclass Program\r\n{\r\n\tstatic void Main(string[] args)\r\n\t{\r\n\t\tusing (var mmf = MemoryMappedFile.CreateFromFile(\"history.dat\",FileMode.Create,null,256))\r\n\t\tusing (var va = mmf.CreateViewAccessor())\r\n\t\t{\r\n\t\t\tvar history = new History();\r\n\t\t\thistory.FileTime = -2;\r\n\t\t\thistory.Price = -2;\r\n\t\t\thistory.Amount = -2;\r\n\r\n\t\t\tva.Write(Marshal.SizeOf(history), ref history);\r\n\t\t\thistory = new History();\r\n\t\t\tva.Read(Marshal.SizeOf(history), out history);\r\n\t\t}\r\n\t}  \r\n}<\/pre>\n<p>\u6ce8\u610f\u70b9\u306f\u3001\u69cb\u9020\u4f53\u306bstring\u306a\u3069\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u542b\u3081\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3002\u578b\u306e\u30b5\u30a4\u30ba\u304c\u3088\u304f\u308f\u304b\u3089\u306a\u304f\u306a\u308b\u304b\u3089\u304b\u306a\uff1f\uff08\u3044\u3084\u305d\u306e\u305d\u3082\u30d0\u30a4\u30ca\u30ea\u30ec\u30d9\u30eb\u3067\u305d\u3093\u306a\u306e\u30a4\u30b8\u3063\u3061\u3083\u3044\u3051\u306a\u3044\u3088\u306d\u666e\u901a\u2026\uff09<\/p>\n<p>\u3042\u3068\u3001\u69cb\u9020\u4f53\u306e\u30b5\u30a4\u30ba\u306fMarshal.SizeOf\u3092\u4f7f\u3063\u3066\u53d6\u5f97\u3002sizeof\u3063\u3066\u306e\u304c\u666e\u901a\u306b\u4f7f\u3048\u305d\u3046\u3060\u3051\u3069\u3001\u69cb\u9020\u4f53\u306b\u306f\u4f7f\u3048\u306a\u3044\u3063\u307d\u3044\u3002Marshal\u3063\u3066\u306e\u304c\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u306b\u95a2\u3059\u308b\u3082\u306e\u3089\u3057\u304f\u3001Marshal.SizeOf\u3067\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u5f8c\u306e\u30b5\u30a4\u30ba\u304c\u53d6\u308c\u308b\u3068\u306e\u3053\u3068\u3002<\/p>\n<p>\u305d\u3082\u305d\u3082\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u3063\u3066\u306a\u3093\u3060\u3068\u601d\u3063\u305f\u3089\u3001\u300c<a href=\"https:\/\/tech.blog.aerie.jp\/entry\/2015\/08\/13\/155225\">\u3010\u4fdd\u5b58\u7248\u3011\u69cb\u9020\u4f53\u306e\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u306e\u307e\u3068\u3081 &#8211; \u9df2\u30ce\u5de3<\/a>\u300d\u306b\u3088\u308b\u3068<\/p>\n<blockquote><p>\n\u547c\u3073\u51fa\u3057\u5074\u306e\u30c7\u30fc\u30bf\u306e\u30b3\u30d4\u30fc\u3092\u4f5c\u3063\u3066\u3001\u305d\u308c\u3092\u76f8\u624b\u5074\u306b\u3068\u3063\u3066\u90fd\u5408\u306e\u3044\u3044\u5f62\u5f0f\u306b\u5909\u63db\u3057\u3066\u304b\u3089\u6e21\u3057\u307e\u3059\u3002\n<\/p><\/blockquote>\n<p>\u3068\u306e\u3053\u3068\u3002\u306a\u308b\u307b\u3069\u3001\u3001\u3001\u7d50\u5c40C#\u3068C\u306e\u30c7\u30fc\u30bf\u8868\u73fe\u306e\u9055\u3044\u3092\u5438\u53ce\u3059\u308b\u8a71\u3060\u3063\u305f\u304b\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u5b9f\u969b\u3067\u304d\u305f\u30d0\u30a4\u30ca\u30ea\u306f\u3053\u3093\u306a\u611f\u3058\u3002\u3061\u3083\u3093\u3068\u66f8\u304d\u8fbc\u3081\u3066\u3044\u308b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180709_1.png\" alt=\"\" width=\"611\" height=\"335\" class=\"alignnone size-full wp-image-3407\" srcset=\"https:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180709_1.png 611w, https:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180709_1-300x164.png 300w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/p>\n<p>\u8aad\u307f\u8fbc\u307f\u3082\u5f53\u7136\u3046\u307e\u304f\u8a00\u3063\u3066\u308b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180709_2.png\" alt=\"\" width=\"376\" height=\"184\" class=\"alignnone size-full wp-image-3409\" srcset=\"https:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180709_2.png 376w, https:\/\/soundengine.jp\/wordpress\/tips\/files\/2018\/07\/20180709_2-300x147.png 300w\" sizes=\"auto, (max-width: 376px) 100vw, 376px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u306a\u3093\u3067\u3082\u51e6\u7406\u3059\u308b\u3068\u3044\u3046\u306e\u306f\u6700\u8fd1\u306e\u30c8\u30ec\u30f3\u30c9\u306a\u306e\u304b\u3082\u3057\u308c\u306a\u3044\u3051\u3069 &hellip; <a href=\"https:\/\/soundengine.jp\/wordpress\/tips\/try\/3402\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[33,34],"class_list":["post-3402","post","type-post","status-publish","format-standard","hentry","category-try","tag-c","tag-34"],"_links":{"self":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/3402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/comments?post=3402"}],"version-history":[{"count":11,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/3402\/revisions"}],"predecessor-version":[{"id":3417,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/posts\/3402\/revisions\/3417"}],"wp:attachment":[{"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/media?parent=3402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/categories?post=3402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soundengine.jp\/wordpress\/tips\/wp-json\/wp\/v2\/tags?post=3402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}