visual c++ - Shared memory size calculation c++ -


I am placing two objects in the shared memory , one of them is the class which: / P>

  class GlobalObj {public: unsigned integer counter; Unsigned int label; BullExist; Globals (zero) {} ~ globe (zero) {}; };   

and another is a boost :: mult_index_container that holds that object:

  class TestObj {public: long Id; Unsigned _int64 track 1; Unsigned _int64 track2; Int label; Metadata (zero) {}; ~ Metadata (zero) {}; };   

So when I am creating shared memory, I calculate the size like this:

  // TEST_CONTAINER_SIZE is a constant that is / The maximum number of records that the multi_index container size_t will containerSize = TEST_CONTAINER_SIZE * sizeOf (TestObj); // Shared shared shared shared managed_memory segment (create_only, "SharedMemory", Container Size + Size (GlobalObj)); So when I  TEST_CONTAINER_SIZE = 10000;  I hope I can include the  10000 TestObj  in the multi_index container in the shared code. But when I run the program, it raises an exception with the shared memory size in the  3071th  item  

Is there any upper part of a multi-index container, or what I calculate the size of shared memory, while I am missing something else?

Thank you.

Edit:

So in my current implementation, my multi-index containers and allocations look like this:

  Typedef multi_index_container & lt; TestObs, Index_bal & lt; Ordered_inick & lt; Members & lt; TestObj, Long, and TestObj :: id & gt; & Gt ;, ordered_one_anique & lt; Members & lt; TestObj, unsigned _int64, and TestObj :: track1 & gt; & Gt; & Gt; Promotion: Interprosse :: Managed_Shore_Ammeri :: Allocator & lt; Testob & gt; :: type & gt; ContainerType; Segment = new managed_asharma_memory (Open_one, "SharedMemory"); Data Container = Segment-> Create & lt; Container Type & gt; ("Datacentainer") // The name of the container in shared memory (Container type :: CTOR_ARS_list ()), Segment-> Get_allocator & lt; Test Oz & gt; ());   

So since I know how many items are in my container, what is the most effective and stable way to allocate it?

There is too much overhead for managing the shared memory segment.

Let's actually understand the allottee, allocate the closest range of these objects from the or segment, so that you can make accurate estimations of the amount of correct memory.

In this reply, I compare the number of allocation overheads with ' managed_shared_memory :

  • In one picture a thousand words says:

    Enter image details here

    As you can see, the amount of memory remaining excessive depends on the way in which you manage the allocation.

  • Comments

    Popular posts from this blog

    Java - Error: no suitable method found for add(int, java.lang.String) -

    java - JPA TypedQuery: Parameter value element did not match expected type -

    c++ - static template member variable has internal linkage but is not defined -