Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am trying to write a complex structure which contains many pointers in shared memory .
Do I use hash table implementation in shared memory ?

Thanks in advance
Posted

1 solution

Instead of pointers use offsets (relative for example to the beginning of the shared memory) because the shared memory might be mapped to different offsets in different processes. A hash table implementation with separate chaining consists of a hash array, and an items array (usually without holes in the items array). The hash table entry contains a hash for the item and an index to the first item in the table with the specified hash, in the items table you also link the items that have the same hash by indices. So the hash table isn't a problem if implemented correctly, you should be careful with the data you place in it, the data should be "self contained" so that it doesn't store data outside the hash table otherwise your data must use an allocator that restricts allocations a pool that resides in your shared memory. This allocator thingy becomes hard-to-manage easily so go with self contained items without pointers and allocation instead!

If you write your hash table implementation (lets say a template) then you have to construct it with placement new and destruct it with direct destructor call on the specified shared memory area. http://www.parashift.com/c++-faq-lite/placement-new.html[^]

You can find C++ hash table implementations with google, all you have to modify is changing the pointers to indices.
 
Share this answer
 
v4

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