|
Boost : |
Subject: [boost] boost::hash - different values for the same input?
From: trafdev (trafdev_at_[hidden])
Date: 2015-12-09 15:13:51
Hi.
As per hash_range docs
(http://www.boost.org/doc/libs/1_59_0/doc/html/hash/reference.html#boost.hash_range_idp93681104):
"This hash function is not intended for general use, and isn't
guaranteed to be equal during separate runs of a program - so please
don't use it for any persistent storage or communication."
As per code
(http://www.boost.org/doc/libs/1_59_0/boost/functional/hash/hash.hpp) it
uses hash_combine_impl which doesn't use any random, process_id etc
values which might change during new process launches.
At the same time, in an example describing container usage in the shared
memory
(http://www.boost.org/doc/libs/1_59_0/doc/html/interprocess/allocators_containers.html#interprocess.allocators_containers.additional_containers),
boost::hash is being used:
typedef boost::unordered_map
< KeyType , MappedType
, boost::hash<KeyType> ,std::equal_to<KeyType>
, ShmemAllocator>
MyHashMap;
My question is: is it safe to use boost::hash in a shared (persistent)
storage or it's safe only for a particular (non-pointer) types?
In this case, boost::hash docs should be changed to mention this
exceptions, because otherwise no one could use boost::hash in a shared
memory containers.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk