Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi ,

I want to implement a hash table in shared memory .
Each entry in hash table contains id ( int ) and values ( int ).
One process should update this shared hash table and the other process should read this table .

I found this implementation very confusing . I tried to implement this using STL map , but this also does not work .

Can any one provide this implementation .

Thanks in advance
Posted

STL has a hash already you can choose between hash_map, hash_multimap.
The only thing that is missing for you is that is not thread safe. So that part you will have to implement yourself.
 
Share this answer
 
The difficulties you have, and which show in your recent posts, are not the hash table itself, but sharing it between processes via shared memory. The particular difficulty is that in shared memory you cannot generally use pointers, because this section of memory might appear at different addresses in the various processes. The solution:

Either implement a hash table that uses only offsets instead of pointers, or use a totally different approach of inter-process communication, for example designating one server process holding the hash table and have all other processes communicate with that server process via remote procedure calls -- a classical database server concept if you will.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900