c++ - How do I measure the size of a boost interprocess vector in shared memory? -


"itemprop =" text ">

I am using boost :: interprocess :: vector to share some strings between processes, and what do I do to me Want to make sure that in the shared memory segment he does not overflow?

I think how much space does the vector take in memory, and how much memory will take a special segment-allocated string?

  boost typedef :: interprocess :: managed_shared_memory :: segment_manager Segment Manager; Typedef boost :: interprocess :: allocation & lt; Char, Segment Manager & gt; CharAllocator; Typedef boost :: interprocess :: basic_string & lt; Char, std :: char_traits & lt; Char & gt ;, char alacrott & gt; ShmString; Typeface Promotion :: Interpreting :: Allocator & Lt; SMT String, Segment Manager & gt; StringAllocator; Typedef boost :: interprocess :: vector & lt; ShmString, string oscillator & gt; ShmStringVector; Const size_t SEGMENT_SIZE = ...; AddToSharedVector (std :: string localString) {Namespace boost :: interprocess; Managed_shared_memory clause (open_only only, kSharedMemorySegmentName); ShmStringVector * shmvector = segment.find & lt; ShmStringVector & gt; (KSharedMemoryVectorName). First; Size_t currentVectorSizeInShm = ??? (Shmvector); & Lt; -------- HALP! Size_t sizeOfNewStringInSharedMemory = ????? (Local string); & Lt; -------- // Not shown for clarity if shared mutex (currentVectorSizeInShm + sizeOfNewStringInSharedMemory & lt; SEGMENT_SIZE) {CharAllocator charAllocator (segment.get_segment_manager ()); ShmString shmString; ShmFunctionName = localString.c_str (); Shmvector-> Push_back (shmString); }}    

  1. quick and dirty

    You can create a physically mapped file to shared memory and can see how many pages are actually committed to the disk. This gives you some kind of indication on many implementations because the pages are most likely 1 page from time to time, and normal memory pages are 4kb.

    I have another answer [1] which tells you the basics of this method.

  2. You can use the get_free_memory () on the Segment Manager to note that it does not say what is allocated / just / that is for vector, but it will give you a ( Arguably more useful) gives the idea of ​​how many places actually captured . In

    [2] I have used that data containers with contiguous storage versus node-based containers Between the memory of the benchmark differences in the middle of the land.

    Enter image details here

    As you can see The person is above the allocation, and the reallocation leads to fragmentation really quick. Then it

    • to prevent space reallocations ahead of the time reserved
    • To make better use of shared memory area using special boost interprocess allocators [1]

      > [2] see

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -