Boost C++ Libraries: Ticket #8276: Shared Memory Access by 32-bit and 64-bit Processes https://svn.boost.org/trac10/ticket/8276 <p> Problem: Exception raised in Segment.find_or_construct&lt;&gt;() call. </p> <pre class="wiki">Problem: Exception raised in Segment.find_or_construct&lt;&gt;() call. The system operates if all of the the processes are 64-bit, or if all of the processes are 32-bit. If the shared memory segment has been constructed by a 64-bit process, attempting to find_or_construct it with a 32-bit process fails. Similary, if the shared memory segment has been constructed by a 32-bit process, attempting to find_of_construct it with a 64-bit process fails. I have determined that the actual objects in shared memory report different sizes when compiled for 32-bit or 64-bit. This is a multi-cast PubSub program. It constructs the following complex data structure in shared memory: // Boost includes #include &lt;boost\interprocess\managed_shared_memory.hpp&gt; #include &lt;boost\interprocess\containers\map.hpp&gt; #include &lt;boost\unordered_map.hpp&gt; #include &lt;boost\interprocess\allocators\allocator.hpp&gt; #include &lt;boost\interprocess\containers\vector.hpp&gt; #include &lt;boost\interprocess\containers\string.hpp&gt; #include &lt;boost\interprocess\sync\interprocess_mutex.hpp&gt; #include &lt;boost\interprocess\sync\interprocess_semaphore.hpp&gt; #include &lt;boost\interprocess\sync\scoped_lock.hpp&gt; #include &lt;boost\interprocess\detail\move.hpp&gt; #include &lt;boost\thread.hpp&gt; #include &lt;boost\foreach.hpp&gt; #include &lt;boost\format.hpp&gt; #include &lt;functional&gt; #include &lt;boost/functional/hash.hpp&gt; typedef managed_shared_memory::segment_manager segment_manager_t; // this is the segment_manager // Define the allocators. typedef boost::interprocess::allocator&lt;void, segment_manager_t&gt; void_allocator; // void_allocator is convertible to any other allocator&lt;T&gt;. typedef boost::interprocess::allocator&lt;int, segment_manager_t&gt; int_allocator; // allocator for allocating ints. typedef boost::interprocess::vector&lt;int, int_allocator&gt; int_vector; // an int_vector is a vector of ints. typedef boost::interprocess::allocator&lt;int_vector, segment_manager_t&gt; int_vector_allocator; // an allocator for allocating vectors of ints. typedef boost::interprocess::vector&lt;int_vector, int_vector_allocator&gt; int_vector_vector; // an int_vector_vector is a vecctor of (vectors of ints) typedef boost::interprocess::allocator&lt;interprocess_semaphore, segment_manager_t&gt; semaphore_allocator; // an allocator for interprocess_semaphore typedef boost::interprocess::allocator&lt;WCHAR, segment_manager_t&gt; wchar_allocator; // an allocator for wide chars. typedef boost::interprocess::basic_string&lt;WCHAR, std::char_traits&lt;WCHAR&gt;, wchar_allocator&gt; wchar_string; // a basic_string (which supports formatting). This is built on a collection of wide chars, allocated by wchar_alloctor. class EventMessage { EnumEventType EventType_; // an enum EnumEventSubType EventSubType; // an enum ULONG32 ProcessId_; ULONG32 ThreadId_; EnumMyType MyType_; // an enum wchar_string FullPath_; GUID GuidPublisher_; } // Event allocators typedef boost::interprocess::allocator&lt;EventMessage, segment_manager_t&gt; EventMessage_allocator; // allocator for allocating EventMessage typedef boost::interprocess::vector&lt;EventMessage, EventMessage_allocator&gt; EventMessage_vector; // vector of EventMessage objects. class Subscription { ULONG32 uSignature_; ULONG32 uSubscribingProcessId_; ULONG32 uSubscribingThreadId_; EnumEventType nEventType_ // an enum offset_ptr&lt;interprocess_semaphore&gt; pSemaphoreSubscription_; GUID guidSubscriber_; BOOL fDestructed; BOOL fWaiting_; BOOL fCancelled_; EventMessage_vector events_; // a shared memory vector of EventMessage } // Define the types related to Subscription typedef boost::interprocess::allocator&lt;Subscription, segment_manager_t&gt; subscription_allocator; // allocator for allocating Subscription typedef boost::interprocess::allocator&lt;GUID, segment_manager_t&gt; guid_allocator; // allocator for allocating GUID typedef std::pair&lt;const GUID, Subscription&gt; pair_guid_subscription; // a pair of GUID, Subscription typedef boost::interprocess::allocator&lt;EnumEventType, segment_manager_t&gt; eventtype_allocator; // allocator for allocating EnumEventType typedef boost::interprocess::allocator&lt;pair_guid_subscription, segment_manager_t&gt; pair_guid_subscription_allocator; // allocator for pair_guid_subscription typedef boost::unordered_map&lt;GUID, Subscription, boost::hash&lt;GUID&gt;, std::equal_to&lt;GUID&gt;, pair_guid_subscription_allocator&gt; guid_subscription_map; // a map of GUID =&gt; Subscription typedef std::pair&lt;const EnumEventType, guid_subscription_map&gt; pair_eventtype_pair_guid_subscription; // a pair(EnumEventType, pair(GUID, Subscription)) typedef boost::interprocess::allocator&lt;pair_eventtype_pair_guid_subscription, segment_manager_t&gt; pair_eventtype_pair_guid_subscription_allocator; // allocator for pair(EnumEventType, pair(GUID, Subscription)) typedef boost::unordered_map&lt;EnumEventType, guid_subscription_map, boost::hash&lt;int&gt;, std::equal_to&lt;int&gt;, pair_eventtype_pair_guid_subscription_allocator&gt; eventtype_map_guid_subscription_map; // a map(EnumEventType, map&lt;GUID, Subscription)&gt; typedef boost::interprocess::vector&lt;Subscription, subscription_allocator&gt; subscription_vector; // a vector of Subscriptions typedef boost::interprocess::allocator&lt;subscription_vector, segment_manager_t&gt; subscription_vector_allocator; // allocator for allocating a vector of Subscription. typedef boost::interprocess::allocator&lt;guid_subscription_map, segment_manager_t&gt; guid_subscription_map_allocator; // allocator for allocating a map of GUID =&gt; Subscription typedef boost::interprocess::allocator&lt;eventtype_map_guid_subscription_map, segment_manager_t&gt; eventtype_map_guid_subscription_map_allocator; // allocator for allocating map&lt;EnumEventType, map&lt;GUID, Subscription&gt;&gt; // This is the single item defined in the segment class Base { uint64_t reserved1_; uint64_t reserved2_; ULONG32 uSignature_; interprocess_mutex mutexSharedMemory_ eventtype_map_guid_subscription_map subscriptions_; // a shared memory map of [GUID, Subscription] (the active subscriptions) } The following sizes are reported: 64-bit sizeof(IntPtr): 8 sizeof(ULONG32): 4 sizeof(BOOL): 4 sizeof(EnumEventType): 4 sizeof(EnumEventSubType): 4 sizeof(EnumCloudAppIconBadgeType): 4 sizeof(GUID): 16 sizeof(EventMessage): 72 sizeof(Subscription): 88 sizeof(Base): 104 sizeof(size_t): 8 32-bit: sizeof(IntPtr): 4 sizeof(ULONG32): 4 sizeof(BOOL): 4 sizeof(EnumEventType): 4 sizeof(EnumEventSubType): 4 sizeof(EnumCloudAppIconBadgeType): 4 sizeof(GUID): 16 sizeof(EventMessage): 60 sizeof(Subscription): 64 sizeof(Base): 72 sizeof(size_t): 4 Note that all of the fundamental types are the same size, but the Boost interprocess sizes are different. I thought that as of Boost 1.48 all of the sizes were normalized to use the same shared memory sizes whether compiled for 32- or 64-bit. Perhaps I am doing something wrong. Suggestions will be welcome. Thanks. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8276 Trac 1.4.3 ingmar.koecher@… Thu, 07 Apr 2016 14:14:10 GMT <link>https://svn.boost.org/trac10/ticket/8276#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8276#comment:1</guid> <description> <p> I'm having a similar issue in Boost 1.57 that I believe is related. A boost vector created in shared memory inside a 64-bit process cannot be "found" in a 32-bit process. It works correctly if both processes are 32-bit. </p> <p> While the shared memory can be opened, the object inside cannot be found. </p> </description> <category>Ticket</category> </item> </channel> </rss>