On 11/10/2017 11:11, Hans Dembinski via Boost wrote:
Hi Ion,
On 11. Oct 2017, at 10:21, Ion Gaztañaga via Boost
wrote: On 10/10/2017 10:02, Hans Dembinski via Boost wrote:
Hi Ion,
On 10. Oct 2017, at 00:17, Ion Gaztañaga via Boost
wrote: There is a related (not a replacement) utility in Boost.Intrusive, used to store additional bits in red-black and AVL trees:
http://www.boost.org/doc/libs/1_65_1/boost/intrusive/pointer_plus_bits.hpp http://www.boost.org/doc/libs/1_65_1/boost/intrusive/pointer_plus_bits.hpp
It assumes the conversion between pointers and integers preserves the alignment in the lower bits of the integer. There are some esoteric platforms where this might not be true, but Boost.Intrusive does not support them. ah, thanks, I didn't know that one. I thought Boost.Intrusive was about containers only, so I would never have looked there. Seeing how pointer_plus_bits is used in Boost.Intrusive, it seems that it is not really intended for users, and serves more as an utility for the library. It is not advertised in the documentation either.
Right now it's used internally and shared with Boost.Interprocess. But obviously we could make them public. The main point is that an utility to embed bits in pointers could consider also fancy pointers.
Yes, you are right. I think that's the way to go.
I am still a bit puzzled how pointer_plus_bits is used in Boost.Intrusive. As far as I can see by reading the code, in boost/intrusive/detail/rbtree_node.hpp and boost/intrusive/detail/avltree_node.hpp it is simply assumed that one or two bits from the pointer can be harvested. There is no platform-check and no general fallback solution. If I used this code on a platform where the assumptions related to bit harvesting are violated, I would trip a BOOST_INTRUSIVE_INVARIANT_ASSERT at runtime instead of crashing, but I could not run the software on such a system.
Which platforms are supported by Boost.Intrusive? Does it work on an ARM processor? The documentation does not say anything about that. That is a bit scary, to be honest. I always assumed that Boost libraries are platform-independent unless explicitly stated otherwise.
Nodes use the trait "max_pointer_plus_bits". If N bits are needed and node type's alignment is at least 2^N bytes, then pointer_plus_bits is used, otherwise, normal pointers are used. An static assert could and maybe should go in pointer_traits, but the check is done at compile time before being used. Best, Ion