Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. sharing standard maps across process boundaries using shared memory concept

sharing standard maps across process boundaries using shared memory concept

Scheduled Pinned Locked Moved ATL / WTL / STL
helpsysadminperformance
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neelesh K J Jain
    wrote on last edited by
    #1

    Hello All, I have a standard map of type map populated in one process and retrieving the values in another process using shared memory concept. The memory is being shared from the server and the client is retrieving the number of pair, but not the values. I am using the following code on the client side for retrieving

    HANDLE hOptimizationShared = OpenFileMapping(FILE\_MAP\_READ, FALSE, szOptimizationShared );
    
    if ( hOptimizationShared != NULL )
    {
    	pOptimizeBuffer = (std::map \*)MapViewOfFile(hOptimizationShared, FILE\_MAP\_READ, 0, 0, 0);
    	HANDLE hEvent;
    
    	if ( pOptimizeBuffer != NULL )
    	{
    		mapFileDetails.insert(pOptimizeBuffer->;begin(),pOptimizeBuffer->;end());
    
    		UnmapViewOfFile(pOptimizeBuffer);
                }
        }
    

    The second condition check is getting validated, and i can see proper size of the map, but the elements are not present. Please help in solving this issue. Thanks in advance. Regards, Neelesh K J Jain.

    S 1 Reply Last reply
    0
    • N Neelesh K J Jain

      Hello All, I have a standard map of type map populated in one process and retrieving the values in another process using shared memory concept. The memory is being shared from the server and the client is retrieving the number of pair, but not the values. I am using the following code on the client side for retrieving

      HANDLE hOptimizationShared = OpenFileMapping(FILE\_MAP\_READ, FALSE, szOptimizationShared );
      
      if ( hOptimizationShared != NULL )
      {
      	pOptimizeBuffer = (std::map \*)MapViewOfFile(hOptimizationShared, FILE\_MAP\_READ, 0, 0, 0);
      	HANDLE hEvent;
      
      	if ( pOptimizeBuffer != NULL )
      	{
      		mapFileDetails.insert(pOptimizeBuffer->;begin(),pOptimizeBuffer->;end());
      
      		UnmapViewOfFile(pOptimizeBuffer);
                  }
          }
      

      The second condition check is getting validated, and i can see proper size of the map, but the elements are not present. Please help in solving this issue. Thanks in advance. Regards, Neelesh K J Jain.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      That's because a map uses dynamic memory that either a) lies outside the shared memory area, or b) won't be found because the virtual memory address of the shared memory is different in the two processes. If you need to share a map across processes using shared memory, I'd suggest you use a map that has been expressly designed for that purpose[^]. Oh - and make sure none of the keys or values reference any dynamically allocated memory either, 'cause that won't work either.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      N 1 Reply Last reply
      0
      • S Stuart Dootson

        That's because a map uses dynamic memory that either a) lies outside the shared memory area, or b) won't be found because the virtual memory address of the shared memory is different in the two processes. If you need to share a map across processes using shared memory, I'd suggest you use a map that has been expressly designed for that purpose[^]. Oh - and make sure none of the keys or values reference any dynamically allocated memory either, 'cause that won't work either.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        N Offline
        N Offline
        Neelesh K J Jain
        wrote on last edited by
        #3

        Thanks stuart for the information and reply, but I doubt whether boost/interprocess is present in VC++ 2008. Because I couldn't able to map it. Thanks, Neelesh K J Jain.

        S 1 Reply Last reply
        0
        • N Neelesh K J Jain

          Thanks stuart for the information and reply, but I doubt whether boost/interprocess is present in VC++ 2008. Because I couldn't able to map it. Thanks, Neelesh K J Jain.

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Neelesh K J Jain wrote:

          but I doubt whether boost/interprocess is present in VC++ 2008.

          No it's not - but it's open source and has a nice license, so why not just download it (Boost Consulting have Windows installers for Boost[^] - use the 1.38.0 version) and use it? If you restrict yourself to just what comes with VS2008, you'll make a lot of work for yourself.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          N 1 Reply Last reply
          0
          • S Stuart Dootson

            Neelesh K J Jain wrote:

            but I doubt whether boost/interprocess is present in VC++ 2008.

            No it's not - but it's open source and has a nice license, so why not just download it (Boost Consulting have Windows installers for Boost[^] - use the 1.38.0 version) and use it? If you restrict yourself to just what comes with VS2008, you'll make a lot of work for yourself.

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            N Offline
            N Offline
            Neelesh K J Jain
            wrote on last edited by
            #5

            Hello Stuart, Thanks alot for the information / suggestion. But still I have a doubt. I am not creating either the key or its value dynamically and as well how its possible to recieve the actual size of the map that is shared from other process using the Named Shared memory. Can you please point me into this concept, If you can share any documents or information URL, that would be great so that I can understand much more thoroughly about the maps. Thanks once again, Regards, Neelesh K J Jain.

            S 1 Reply Last reply
            0
            • N Neelesh K J Jain

              Hello Stuart, Thanks alot for the information / suggestion. But still I have a doubt. I am not creating either the key or its value dynamically and as well how its possible to recieve the actual size of the map that is shared from other process using the Named Shared memory. Can you please point me into this concept, If you can share any documents or information URL, that would be great so that I can understand much more thoroughly about the maps. Thanks once again, Regards, Neelesh K J Jain.

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              Neelesh K J Jain wrote:

              I am not creating either the key or its value dynamically and as well how its possible to recieve the actual size of the map that is shared from other process using the Named Shared memory

              The map definition in Visual Studio's map class is effectively this:

              template
              class map
              {
              _TreeNode >* _Myhead;
              size_type size;
              };

              _TreeNode is this:

              template
              class _TreeNode
              {
              _TreeNode* _Left;
              _TreeNode* _Right;
              _TreeNode* _Parent;
              Value _Myvalue;
              char _Color;
              char _Isnil;
              };

              So, you can see that a map object contains only its size and a pointer to the head of the tree it uses to contain its elements. It uses a red-black tree (I think - or it could be an AVL tree?) because that makes it easy to maintain an element ordering. Does that answer your query?

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              N 1 Reply Last reply
              0
              • S Stuart Dootson

                Neelesh K J Jain wrote:

                I am not creating either the key or its value dynamically and as well how its possible to recieve the actual size of the map that is shared from other process using the Named Shared memory

                The map definition in Visual Studio's map class is effectively this:

                template
                class map
                {
                _TreeNode >* _Myhead;
                size_type size;
                };

                _TreeNode is this:

                template
                class _TreeNode
                {
                _TreeNode* _Left;
                _TreeNode* _Right;
                _TreeNode* _Parent;
                Value _Myvalue;
                char _Color;
                char _Isnil;
                };

                So, you can see that a map object contains only its size and a pointer to the head of the tree it uses to contain its elements. It uses a red-black tree (I think - or it could be an AVL tree?) because that makes it easy to maintain an element ordering. Does that answer your query?

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                N Offline
                N Offline
                Neelesh K J Jain
                wrote on last edited by
                #7

                Full Marks, I got it, I was thinking, there is something wrong in my code, for that reason, only the size is being retrieved and not the data. I have an explanation now for using the boost/interprocess/map.hpp Thanks alot. :) :thumbsup: Thanks and Regards, Neelesh K J Jain.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups