Dynamic_bitset and access to underlying storage

Hi, I need to use a bitset with contiguous storage so that I can pass it to a system call. Although I can't see it in the documentation, I know from reading the code, that dynamic bitset is implemented in terms of std::vector. Also, whilst I don't need the run time resizing that dynamic bitset provides, I do need to be able to use up to at least 64K bits, So, is there any chance of an additional member function+ that returns a pointer to the zero'eth element of the underlying vector? regards /ikh -- "I disapprove of what you say, but I will defend to the death your right to say it." Evelyn Beatrice Hall who wrote under the pseudonym S.G. Tallentyre in a biography of Voltaire. #include <std_disclaimer>

Iain K. Hanson wrote:
Hi,
I need to use a bitset with contiguous storage so that I can pass it to a system call. Although I can't see it in the documentation, I know from reading the code, that dynamic bitset is implemented in terms of std::vector.
Also, whilst I don't need the run time resizing that dynamic bitset provides, I do need to be able to use up to at least 64K bits,
So, is there any chance of an additional member function+ that returns a pointer to the zero'eth element of the underlying vector?
regards
/ikh
I encountered a similar problem when trying to serialize an object that had a dynamic_bitset as a member. http://comments.gmane.org/gmane.comp.lib.boost.devel/198466 Taking a lead from how std::bitset is serialized, I limited myself to the existing API. However that's only a limitation with std objects where the API is frozen. With boost::dynamic_bitset I should have taken advantage of the ability to change the source and made the serialization functions friends. Instead I made use of boost::dynamic_bitset::to_block_range(). If that meets your needs, you can avoid an API change. See dynamic_bitset.hpp within my ZIP file for an example. http://www.boostpro.com/vault/index.php?directory=serialization Thanks, Paul

Zitat von Paul Fee <pfee@talk21.com>:
I need to use a bitset with contiguous storage so that I can pass it to a system call. Although I can't see it in the documentation, I know from reading the code, that dynamic bitset is implemented in terms of std::vector.
Also, whilst I don't need the run time resizing that dynamic bitset provides, I do need to be able to use up to at least 64K bits,
So, is there any chance of an additional member function+ that returns a pointer to the zero'eth element of the underlying vector?
I encountered a similar problem when trying to serialize an object that had a dynamic_bitset as a member.
I encountered a similar problem when trying to use another vector implementation (similar to auto_buffer in the review queue) with dynamic_bitset. all of these problems could be solved if dynamic_bitset was changed into a container adapter similar to std::stack and leave the underlying container to the user.

Stefan Strasser wrote:
all of these problems could be solved if dynamic_bitset was changed into a container adapter similar to std::stack and leave the underlying container to the user.
That seems like a neat idea. In the meantime, [1] GotW #76 warns us not to do this... #include <boost/dynamic_bitset.hpp> typedef unsigned long block_t; namespace { struct weasel { block_t* ptr; }; } namespace boost { template <> template <> void dynamic_bitset< block_t >::append( weasel* first, weasel* last ) { first->ptr = &m_bits[0]; last->ptr = &m_bits[0] + m_bits.size(); } } #include <iostream> int main( int argc, char* const argv[] ) { boost::dynamic_bitset< block_t > db; db.append( 42 ); weasel first = {0}, last = {0}; db.append( &first, &last ); std::cout << "size: " << last.ptr - first.ptr; std::cout << " first element: " << *first.ptr << std::endl; return 0; } ;-) Gareth [1] http://www.gotw.ca/gotw/076.htm ************************************************************************ The information contained in this message or any of its attachments may be confidential and is intended for the exclusive use of the addressee(s). Any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited without the express permission of the sender. The views expressed in this email are those of the individual and not necessarily those of Sony or Sony affiliated companies. Sony email is for business use only. This email and any response may be monitored by Sony to be in compliance with Sony's global policies and standards
participants (4)
-
Iain K. Hanson
-
Paul Fee
-
Stefan Strasser
-
Sylvester-Bradley, Gareth