sharing standard maps across process boundaries using shared memory concept
-
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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.
-
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.
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
-
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
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.