{"id":3126,"date":"2012-05-20T19:10:58","date_gmt":"2012-05-21T02:10:58","guid":{"rendered":"http:\/\/www.jinmei.org\/blog\/?p=3126"},"modified":"2012-05-23T23:57:53","modified_gmt":"2012-05-24T06:57:53","slug":"boost-offset_ptr%e3%81%a8%e5%85%b1%e6%9c%89%e3%83%a1%e3%83%a2%e3%83%aa%e3%81%a8mmap","status":"publish","type":"post","link":"https:\/\/www.jinmei.org\/blog\/2012\/05\/20\/3126","title":{"rendered":"Boost offset_ptr\u3068\u5171\u6709\u30e1\u30e2\u30ea\u3068mmap"},"content":{"rendered":"<p>\u67d0\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u305f\u3081\u306e\u5b9f\u76ca\u3082\u517c\u306d\u3066Boost\u306e\u5171\u6709\u30e1\u30e2\u30ea\u7cfb\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u904a\u3093\u3067\u307f\u305f\u3002offset_ptr\u304c\u304b\u306a\u308a\u76f4\u611f\u7684\u306b\u4f7f\u3048\u308b\u306e\u3067\u3001\u5171\u6709\u30e1\u30e2\u30ea\u3092\u4f7f\u308f\u306a\u3044\u30b3\u30fc\u30c9\u3092\u307e\u305a\u305d\u308c\u3067\u66f8\u3044\u3066\u307f\u3066\u3001\u306e\u3061\u306e\u3061\u5171\u6709\u30e1\u30e2\u30ea\u578b\u306e\u5b9f\u88c5\u306b\u767a\u5c55\u3055\u305b\u308b\u3068\u3044\u3046\u306e\u306f\u6bd4\u8f03\u7684\u7c21\u5358\u306b\u3067\u304d\u305d\u3046\u3002\u3042\u3068\u3001managed_shared_memory\u3068managed_mapped_file\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3068\u3001\u5171\u6709\u30e1\u30e2\u30ea\u4e0a\u306e\u30e1\u30e2\u30ea\u7ba1\u7406(\u52d5\u7684\u306a\u9818\u57df\u306e\u78ba\u4fdd\u3068\u89e3\u653e\u3001\u3055\u3089\u306b\u78ba\u4fdd\u3057\u305f\u9818\u57df\u4e0a\u3067\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u69cb\u7bc9)\u3082\u307b\u307c\u304a\u307e\u304b\u305b\u3067\u3067\u304d\u308b\u306e\u3067\u3001\u5c11\u306a\u304f\u3068\u3082\u30e1\u30e2\u30ea\u7ba1\u7406\u306e\u52b9\u7387\u3068\u304b\u3092\u6c17\u306b\u3057\u306a\u3044\u7bc4\u56f2\u3067\u306a\u3089\u5171\u6709\u30e1\u30e2\u30ea\u5bfe\u5fdc\u3082\u7d50\u69cb\u7c21\u5358\u306b\u3067\u304d\u305d\u3046\u3002<br \/>\n<!--more--><br \/>\n\u4f8b\u984c\u3068\u3057\u3066\u5358\u7d14\u306a\u4e00\u65b9\u5411linked list\u3092\u3044\u3058\u308b\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u307f\u305f\u3002\u4ee5\u4e0b\u306f\u30ea\u30b9\u30c8\u306e\u30a8\u30f3\u30c8\u30ea\u306e\u5b9a\u7fa9\u3002\u30e1\u30f3\u30d0\u3068\u3057\u3066&#8221;next&#8221;\u3078\u306e\u30dd\u30a4\u30f3\u30bf\u3068\u30a8\u30f3\u30c8\u30ea\u306e\u5024(int)\u3092\u6301\u3064\u3001\u3088\u304f\u3042\u308b\u5b9a\u7fa9\u3060\u3051\u3069\u3001next\u304c<code>Entry*<\/code>\u3058\u3083\u306a\u304f\u3066<code>offset_ptr<\/code>\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u3053\u308d\u304c\u9055\u3046\u3002<\/p>\n<p><code>allocate<\/code>\u3068<code>deallocate<\/code>\u306f\u30ea\u30b9\u30c8\u30a8\u30f3\u30c8\u30ea\u3092\u52d5\u7684\u306b\u751f\u6210\u30fb\u7834\u68c4\u3059\u308b\u305f\u3081\u306e<code>new<\/code>\u3068<code>delete<\/code>\u76f8\u5f53\u306e\u95a2\u6570\u3002\u7a2e\u3005\u306e(\u5171\u6709)\u30e1\u30e2\u30ea\u7ba1\u7406\u65b9\u5f0f\u306b\u4e00\u62ec\u3057\u3066\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u3057\u3066\u3044\u308b\u3002<code>SegmentType<\/code>\u3068\u3057\u3066\u306f\u305f\u3068\u3048\u3070<code>managed_shared_memory<\/code>\u3092\u60f3\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\nstruct Entry;\r\ntypedef offset_ptr&lt;Entry&gt; EntryPtr;\r\n\r\nstruct Entry {\r\n    EntryPtr next;\r\n    const int value;\r\n\r\n    Entry(int val) : next(NULL), value(val) {}\r\n    template &lt;typename SegmentType&gt;\r\n    static Entry* allocate(SegmentType& segment, int i);\r\n    template &lt;typename SegmentType&gt;\r\n    static void deallocate(SegmentType& segment, EntryPtr ep) {\r\n        segment.destroy_ptr(ep.get());\r\n    }\r\n};\r\n<\/pre>\n<p>\u4ee5\u4e0b\u306e\u4e8c\u3064\u306fBoost\u306emanaged_shared_memory\u3068managed_mapped_file\u306e\u305f\u3081\u306e<code>allocate<\/code>\u306e\u5b9a\u7fa9\u3002managed_xxx\u306f\u3068\u3082\u306b\u5185\u90e8\u306b\u30e1\u30e2\u30ea\u30a2\u30ed\u30b1\u30fc\u30bf(\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8\u3082\u3084\u3063\u3066\u304f\u308c\u308b)\u3082\u5099\u3048\u3066\u3044\u308b\u306e\u3067\u5358\u306b\u305d\u308c\u3092\u547c\u3076\u3060\u3051\u3002\u3053\u308c\u3089\u306f\u5171\u6709\u30e1\u30e2\u30ea\u3092\u53c2\u7167\u3057\u3066\u3044\u308b\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u5358\u4e00\u306e\u8b58\u5225\u5b50\u3067\u53c2\u7167\u3055\u308c\u308b\u5fc5\u8981\u306f\u306a\u3044(\u3059\u3067\u306b\u77e5\u3063\u3066\u3044\u308b\u30dd\u30a4\u30f3\u30bf\u304b\u3089\u305f\u3050\u3063\u3066\u3044\u3051\u308b\u306f\u305a)\u306e\u3067<code>anonymous_instance<\/code>\u3092\u6307\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\ntemplate &lt;&gt;\r\nEntry*\r\nEntry::allocate&lt;managed_shared_memory&gt;(\r\n    managed_shared_memory& segment, int i) \r\n{\r\n    return (segment.construct&lt;Entry&gt;(\r\n                anonymous_instance)(i));\r\n}\r\n\r\ntemplate &lt;&gt;\r\nEntry*\r\nEntry::allocate&lt;managed_mapped_file&gt;(\r\n    managed_mapped_file& segment, int i) \r\n{\r\n    return (segment.construct&lt;Entry&gt;(\r\n                anonymous_instance)(i));\r\n}\r\n<\/pre>\n<p>\u6b21\u304c\u5927\u4e8b\u306a\u90e8\u5206: \u30ea\u30b9\u30c8\u306b\u8981\u7d20\u3092\u8ffd\u52a0\u3001\u30ea\u30b9\u30c8\u304b\u3089\u8981\u7d20\u3092\u524a\u9664\u3001\u30ea\u30b9\u30c8\u3092\u306a\u3081\u3066\u5185\u5bb9\u3092\u8868\u793a\u3059\u308b\u95a2\u6570\u3002\u8ffd\u52a0\u3068\u524a\u9664\u3067\u306f\u30e1\u30e2\u30ea\u7ba1\u7406\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5316\u3057\u305f\u4e0a\u3067<code>SegmentType<\/code>\u3092\u6e21\u3057\u3066\u3044\u308b\u3002\u91cd\u8981\u306a\u306e\u306f<code>EntryPtr<\/code>(<code>offset_ptr<\/code>)\u306e\u4f7f\u3044\u65b9\u3002\u3053\u306e\u30b3\u30fc\u30c9\u81ea\u4f53\u306f<code>offset_ptr<\/code>\u578b\u306e\u7279\u5fb4\u306b\u306f\u4f9d\u5b58\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3001<code>Entry*<\/code>\u3068(\u307b\u307c)\u4e92\u63db\u6027\u306e\u3042\u308b\u5f62\u306b\u306a\u3063\u3066\u3044\u308b\u3002(get_offset()\u3060\u3051\u306foffset_ptr\u30af\u30e9\u30b9\u4f9d\u5b58\u3060\u3051\u3069\u3001\u3053\u308c\u306f\u3053\u3053\u3067\u306e\u4f5c\u696d\u306e\u672c\u8cea\u3067\u306f\u306a\u304f\u3066\u30c7\u30d0\u30c3\u30b0\u7528\u51fa\u529b\u306a\u306e\u3067\u7121\u8996\u3057\u3066\u3088\u3044)<\/p>\n<pre class=\"codefrag\">\r\ntemplate &lt;typename SegmentType&gt;\r\nvoid\r\naddListEntry(SegmentType& segment,\r\n             EntryPtr* list_head,\r\n             int i)\r\n{\r\n    EntryPtr* prev = list_head;\r\n    while (*prev) {\r\n        prev = &(*prev)-&gt;next;\r\n    }\r\n    *prev = Entry::allocate(segment, i);\r\n}\r\n\r\ntemplate &lt;typename SegmentType&gt;\r\nvoid\r\nremoveListEntry(SegmentType& segment,\r\n                EntryPtr* list_head, int i)\r\n{\r\n    EntryPtr* prev = list_head;\r\n    for (EntryPtr ep = *list_head;\r\n         ep;\r\n         ep = ep-&gt;next)\r\n    {\r\n        if (ep-&gt;value == i) {\r\n            *prev = ep-&gt;next;\r\n            Entry::deallocate(segment, ep);\r\n            return;\r\n        }\r\n        prev = &(*prev)-&gt;next;\r\n    }\r\n}\r\n\r\n\/\/ 'head' can be of '(const) EntryPtr&', too.\r\nvoid\r\ntraverseList(EntryPtr head) {\r\n    for (EntryPtr ep = head;\r\n         ep;\r\n         ep = ep-&gt;next)\r\n    {\r\n        cout &lt;&lt; ep-&gt;value &lt;&lt; endl;\r\n        if (ep-&gt;next) {\r\n            cout &lt;&lt; ep-&gt;next.get_offset() &lt;&lt; endl;\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>\u4ee5\u4e0a\u306e\u9053\u5177\u3092\u5229\u7528\u3057\u3066\u3001\u5171\u6709\u30e1\u30e2\u30ea\u4e0a\u306b10\u30a8\u30f3\u30c8\u30ea\u304b\u3089\u6210\u308b\u30ea\u30b9\u30c8\u3092\u4f5c\u3063\u3066\u3001\u305d\u308c\u3092\u5b50\u30d7\u30ed\u30bb\u30b9\u306b\u624b\u7e70\u3089\u305b\u3066\u524a\u9664\u3001\u3068\u3044\u3046\u3053\u3068\u3092\u3059\u308b\u30c6\u30b9\u30c8\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u4ee5\u4e0b\u3002\u30ea\u30b9\u30c8\u306e\u5148\u982d\u3092\u6307\u3059\u30dd\u30a4\u30f3\u30bf(offset_ptr)\u81ea\u4f53\u3082\u5171\u6709\u30e1\u30e2\u30ea\u4e0a\u306b\u683c\u7d0d\u3057\u3001\u305d\u308c\u306b\u306f&#8221;head&#8221;\u3068\u3044\u3046\u540d\u524d\u3092\u4ed8\u3051\u3066\u5b50\u30d7\u30ed\u30bb\u30b9\u304b\u3089\u53c2\u7167\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u3002\u5b50\u30d7\u30ed\u30bb\u30b9\u306f&#8221;head&#8221;\u3060\u3051\u308f\u304b\u308c\u3070\u3042\u3068\u306foffset_ptr\u3092\u666e\u901a\u306e\u30dd\u30a4\u30f3\u30bf\u3068\u540c\u3058\u3088\u3046\u306b\u4f7f\u3063\u3066\u4ed5\u4e8b\u3092\u3059\u308c\u3070\u3088\u3044\u3002<\/p>\n<pre class=\"codefrag\">\r\nint\r\nmain(int argc, char* argv[]) {\r\n    if (argc == 1) {\r\n        \/\/ parent process: create a shared memory region and build\r\n        \/\/ a linked list there.\r\n        shared_memory_object::remove(\"TestSharedMemory\");\r\n        managed_shared_memory segment(open_or_create,\r\n                                      \"TestSharedMemory\",\r\n                                      4096);\r\n        EntryPtr* list_head =\r\n            segment.construct&lt;EntryPtr&gt;(\"head\")(\r\n                static_cast&lt;Entry*&gt;(NULL));\r\n        for (int i = 0; i &lt; 10; ++i) {\r\n            addListEntry(segment, list_head, i);\r\n        }\r\n        system((string(argv[0]) + \" child\").c_str());\r\n    } else {\r\n        \/\/ child process: open the created shared memory and iterate over\r\n        \/\/ the linked list stored there.\r\n        managed_shared_memory segment(open_only,\r\n                                      \"TestSharedMemory\");\r\n        EntryPtr* list_head =\r\n            (segment.find&lt;EntryPtr&gt;(\"head\").first);\r\n        assert(list_head != NULL);\r\n        traverseList(*list_head);\r\n        for (int i = 0; i &lt; 10; ++i) {\r\n            removeListEntry(segment, list_head, i);\r\n        }\r\n        segment.destroy_ptr(list_head);\r\n        assert(segment.all_memory_deallocated());\r\n    }\r\n}\r\n<\/pre>\n<p>\u540c\u69d8\u306e\u3053\u3068\u3092mapped file\u3067\u3084\u308b\u306e\u304c\u4ee5\u4e0b\u306e\u4f8b\u3002\u3053\u306e\u4f8b\u3067\u306f\u3001\u524d\u534a\u3067map\u7528\u306e\u65b0\u3057\u3044\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u3063\u3066\u305d\u308c\u3092\u30e1\u30e2\u30ea\u306b\u30de\u30c3\u30d7\u3057\u3001\u305d\u306e\u4e0a\u306b\u30ea\u30b9\u30c8\u3092\u751f\u6210\u3002\u5f8c\u534a\u3067\u306f\u6539\u3081\u3066\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30aa\u30fc\u30d7\u30f3\u3057\u3066\u30e1\u30e2\u30ea\u306b\u30de\u30c3\u30d7\u3057\u3001\u305d\u308c\u3092\u8210\u3081\u305f\u4e0a\u3067\u524a\u9664\u3057\u3066\u3044\u308b\u3002\u524d\u534a\u304c<code>if<\/code>\u306e\u4e2d\u306b\u3042\u308b\u306e\u306f\u5ff5\u306e\u305f\u3081\u6700\u521d\u306e<code>managed_mapped_file<\/code>\u304c\u7834\u68c4\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u3002\u307e\u305f\u3001\u524d\u534a\u90e8\u5206\u306e\u6700\u5f8c\u3067flush()\u3092\u547c\u3093\u3067\u30e1\u30e2\u30ea\u306e\u5185\u5bb9\u304c\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u51fa\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b(managed_mapped_file\u306e\u30c7\u30b9\u30c8\u30e9\u30af\u30bf\u3042\u305f\u308a\u3067\u3053\u306e\u51e6\u7406\u3092\u3084\u3063\u3066\u304f\u308c\u308b\u306e\u304b\u3069\u3046\u304b\u8abf\u3079\u3066\u306a\u3044\u304c\u3001\u3044\u308d\u3044\u308d\u8a66\u3057\u3066\u3044\u305f\u6bb5\u968e\u3067\u306fflush\u629c\u304d\u3060\u3068\u52d5\u304b\u306a\u3044\u5834\u5408\u3082\u3042\u3063\u305f\u3088\u3046\u306a)\u3002<\/p>\n<pre class=\"codefrag\">\r\nint\r\nmain(int argc, char**) {\r\n    if (true) {\r\n        file_mapping::remove(\"TestMappedFile\");\r\n        managed_mapped_file segment(open_or_create,\r\n                                    \"TestMappedFile\",\r\n                                    4096);\r\n        EntryPtr* list_head =\r\n            segment.construct&lt;EntryPtr&gt;(\"head\")(\r\n            static_cast&lt;Entry*&gt;(NULL));\r\n        for (int i = 0; i &lt; 10; ++i) {\r\n            addListEntry(segment, list_head, i);\r\n        }\r\n        segment.flush();\r\n    }\r\n\r\n    \/\/ (re)map the file to memory, and examine it.\r\n    managed_mapped_file segment =\r\n        managed_mapped_file(open_only,\r\n                            \"TestMappedFile\");\r\n    EntryPtr* list_head =\r\n        segment.find&lt;EntryPtr&gt;(\"head\").first;\r\n    assert(list_head != NULL);\r\n    traverseList(*list_head);\r\n    for (int i = 0; i &lt; 10; ++i) {\r\n        removeListEntry(segment, list_head, i);\r\n    }\r\n    segment.destroy_ptr(list_head);\r\n    assert(segment.all_memory_deallocated());\r\n}\r\n<\/pre>\n<p>\u3055\u3089\u306b\u3001offset_ptr\u81ea\u4f53\u306f\u5171\u6709\u30e1\u30e2\u30ea\u578b\u306e\u9818\u57df\u3067\u306a\u304f\u3066\u3082\u52d5\u304f\u306e\u3067\u3001\u666e\u901a\u306bnew\/delete\u3059\u308b\u30e1\u30e2\u30ea\u7ba1\u7406\u3067\u540c\u3058\u3053\u3068\u3092\u3084\u3063\u3066\u307f\u305f\u306e\u304c\u4ee5\u4e0b\u306e\u4f8b\u3002<\/p>\n<p>\u307e\u305a\u3001Boost\u306emanged_xxx\u578b\u3092\u60f3\u5b9a\u3057\u305f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3059\u3088\u3046\u306bwrapper\u306e\u30af\u30e9\u30b9(\u3068\u3001\u305d\u308c\u3092\u4f7f\u3063\u305f<code>Entry<\/code>\u7528\u306eallocate\u30e1\u30bd\u30c3\u30c9)\u3092\u5b9a\u7fa9\u3059\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\nclass NormalMemorySegment {\r\npublic:\r\n    NormalMemorySegment() : allocated_(0) {}\r\n    template &lt;typename PointedType&gt;\r\n    void destroy_ptr(PointedType* ptr) {\r\n        assert(allocated_ &gt;= sizeof(PointedType));\r\n        delete ptr;\r\n        allocated_ -= sizeof(PointedType);\r\n    }\r\n    bool all_memory_deallocated() const { return (allocated_ == 0); }\r\n    void addAllocated(size_t allocated_size) {\r\n        allocated_ += allocated_size;\r\n    }\r\nprivate:\r\n    size_t allocated_;\r\n};\r\n\r\ntemplate &lt;&gt;\r\nEntry*\r\nEntry::allocate&lt;NormalMemorySegment&gt;(\r\n    NormalMemorySegment& segment, int i)\r\n{\r\n    Entry* ptr = new Entry(i);\r\n    segment.addAllocated(sizeof(Entry));\r\n    return (ptr);\r\n}\r\n<\/pre>\n<p>\u30e1\u30a4\u30f3\u306e\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u3002\u3082\u3061\u308d\u3093\u3001\u3053\u306e\u5834\u5408\u306f\u8907\u6570\u30d7\u30ed\u30bb\u30b9\u9593\u3067\u30a4\u30e1\u30fc\u30b8\u3092\u5171\u6709\u3057\u305f\u308a\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u51fa\u3057\u305f\u308a\u3068\u304b\u3044\u3063\u305f\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002\u30ea\u30b9\u30c8\u306e\u30d8\u30c3\u30c9\u3092\u6307\u3059\u30dd\u30a4\u30f3\u30bf\u306f\u5358\u306bnew\u3067\u78ba\u4fdd\u3057\u3066\u6700\u5f8c\u306bdelete\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"codefrag\">\r\nint\r\nmain() {\r\n    NormalMemorySegment segment;\r\n\r\n    EntryPtr* list_head = new EntryPtr(NULL);\r\n    for (int i = 0; i &lt; 10; ++i) {\r\n        addListEntry(segment, list_head, i);\r\n    }\r\n    traverseList(*list_head);\r\n    for (int i = 0; i &lt; 10; ++i) {\r\n        removeListEntry(segment, list_head, i);\r\n    }\r\n    delete list_head;\r\n    assert(segment.all_memory_deallocated());\r\n}\r\n<\/pre>\n<p>\u3053\u306e\u4f8b\u306e\u5834\u5408\u306f\u3001<code>EntryPtr<\/code>\u3092\u5358\u306b<code>Entry*<\/code>\u3068\u5b9a\u7fa9\u3057\u3066\u3082(\u3054\u304f\u308f\u305a\u304b\u306a\u4fee\u6b63\u3060\u3051\u3067)\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3059\u308b\u3002\u901a\u5e38\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u4f7f\u3046\u5206\u306b\u306f\u307b\u3068\u3093\u3069\u30dd\u30a4\u30f3\u30bf\u578b\u3068\u540c\u3058\u3060\u3068\u601d\u3063\u3066\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3082\u52d5\u304d\u305d\u3046\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001offset_ptr\u306f\u306a\u304b\u306a\u304b\u3088\u304f\u3067\u304d\u3066\u3044\u308b\u3068\u3044\u3046\u5370\u8c61\u3002\u67d0\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u7684\u306b\u306f\u3001\u3068\u308a\u3042\u3048\u305a\u5b9f\u969b\u306e\u30e1\u30e2\u30ea\u7ba1\u7406\u306b\u306fnew\/delete\u3092\u4f7f\u3044\u3064\u3064\u3001\u30dd\u30a4\u30f3\u30bf\u307e\u308f\u308a\u306f\u3059\u3079\u3066offset_ptr\u3092\u4f7f\u3046\u5f62\u3067\u306f\u3058\u3081\u3066\u3001\u3082\u3046\u5c11\u3057\u5f8c\u3067\u6642\u9593\u304c\u3067\u304d\u305f\u3089\u5171\u6709\u30e1\u30e2\u30ea\u578b\u306b\u79fb\u884c\u3001\u3068\u3044\u3046\u306e\u304c\u3088\u3055\u305d\u3046\u3002\u3053\u308c\u3060\u3068\u30e1\u30a4\u30f3\u306e\u30b3\u30fc\u30c9(\u3068\u304f\u306bread only\u306e\u65b9)\u306f\u307b\u3068\u3093\u3069\u5909\u3048\u305a\u306b\u3001&#8221;head&#8221;\u306b\u76f8\u5f53\u3059\u308b\u90e8\u5206\u3060\u3051\u3092managed_shared_memory\u3068\u304b\u4f7f\u3063\u3066\u53d6\u308a\u51fa\u3059\u3088\u3046\u306b\u3059\u308b\u3060\u3051\u3067\u52d5\u304f\u3068\u671f\u5f85\u3067\u304d\u308b\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001<a href=\"http:\/\/stackoverflow.com\/questions\/3196395\/is-boostinterprocess-ready-for-prime-time?answertab=votes#tab-top\">stackoverflow\u3067\u8b70\u8ad6\u3055\u308c\u3066\u3044\u308b<\/a>\u3088\u3046\u306b\u3001offset_ptr\u306b\u306f\u30c7\u30b6\u30a4\u30f3\u4e0a\u3061\u3087\u3063\u3068\u554f\u984c\u3068\u3044\u3048\u308b\u90e8\u5206\u3082\u3042\u308b\u3002NULL\u30dd\u30a4\u30f3\u30bf\u30a2\u30af\u30bb\u30b9\u304csegmentation fault\u306b\u306a\u3089\u306a\u3044(\u4e0a\u306b\u3001\u66f8\u304d\u8fbc\u307f\u306e\u5834\u5408\u306f\u4efb\u610f\u306e\u9818\u57df\u304c\u7834\u58ca\u3055\u308c\u3066\u3057\u307e\u3046)\u3068\u3044\u3046\u306e\u306f\u78ba\u304b\u306b\u3084\u3063\u304b\u3044\u304b\u3068\u306f\u601d\u3046\u3051\u3069\u3001\u30dd\u30a4\u30f3\u30bf\u3092\u6e21\u3059\u3068\u3053\u308d\u3067\u504f\u57f7\u72c2\u7684\u306bassert()\u3059\u308b\u3068\u304b\u3059\u308c\u3070\u304b\u306a\u308a\u30ab\u30d0\u30fc\u3067\u304d\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3046\u3002\u3082\u3057\u304f\u306f\u3001\u6027\u80fd\u3068\u306e\u30c8\u30ec\u30fc\u30c9\u30aa\u30d5\u306b\u306a\u308b\u3051\u3069\u3001offset_ptr\u306e\u5b9a\u7fa9\u3092\u30b3\u30d4\u3063\u3066\u304d\u3066<code>operator-&gt;<\/code>\u3068\u304b<code>operator*<\/code>\u306e\u3068\u3053\u308d\u3067NULL\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3068\u3044\u3046\u624b\u3082\u3042\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u67d0\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u305f\u3081\u306e\u5b9f\u76ca\u3082\u517c\u306d\u3066Boost\u306e\u5171\u6709\u30e1\u30e2\u30ea\u7cfb\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u904a\u3093\u3067\u307f\u305f\u3002offset_ptr\u304c\u304b\u306a\u308a\u76f4\u611f\u7684\u306b\u4f7f\u3048\u308b\u306e\u3067\u3001\u5171\u6709\u30e1\u30e2\u30ea\u3092\u4f7f\u308f\u306a\u3044\u30b3\u30fc\u30c9\u3092\u307e\u305a\u305d\u308c\u3067\u66f8\u3044\u3066\u307f\u3066\u3001\u306e\u3061\u306e\u3061\u5171\u6709\u30e1\u30e2\u30ea\u578b\u306e\u5b9f\u88c5\u306b\u767a\u5c55\u3055\u305b\u308b\u3068\u3044\u3046\u306e\u306f\u6bd4\u8f03\u7684\u7c21\u5358\u306b\u3067\u304d\u305d\u3046\u3002\u3042\u3068\u3001managed_shared_memory\u3068managed_mapped_file\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3068\u3001\u5171\u6709\u30e1\u30e2\u30ea\u4e0a\u306e\u30e1\u30e2\u30ea\u7ba1\u7406(\u52d5\u7684\u306a\u9818\u57df\u306e\u78ba\u4fdd\u3068\u89e3\u653e\u3001\u3055\u3089\u306b\u78ba\u4fdd\u3057\u305f\u9818\u57df\u4e0a\u3067\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u69cb\u7bc9)\u3082\u307b\u307c\u304a\u307e\u304b\u305b\u3067\u3067\u304d\u308b\u306e\u3067\u3001\u5c11\u306a\u304f\u3068\u3082\u30e1\u30e2\u30ea\u7ba1\u7406\u306e\u52b9\u7387\u3068\u304b\u3092\u6c17\u306b\u3057\u306a\u3044\u7bc4\u56f2\u3067\u306a\u3089\u5171\u6709\u30e1\u30e2\u30ea\u5bfe\u5fdc\u3082\u7d50\u69cb\u7c21\u5358\u306b\u3067\u304d\u305d\u3046\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3126","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts\/3126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/comments?post=3126"}],"version-history":[{"count":12,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts\/3126\/revisions"}],"predecessor-version":[{"id":3140,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/posts\/3126\/revisions\/3140"}],"wp:attachment":[{"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/media?parent=3126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/categories?post=3126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jinmei.org\/blog\/wp-json\/wp\/v2\/tags?post=3126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}