I was wondering how I can save space writing a bitset to a file ( probably using iostream) in c++. Will breaking up the bitset into bitset of size 8 and then writing each individual bitset to the file save me space? What is your thought about this. This is the intention of data compression.
Save space writing bitset to a file in C++
1.7k Views Asked by DogDog At
2
There are 2 best solutions below
0
Rexxar
On
If you use boost::dynamic_bitset instead, you can specify the type of the underlying blocks and retrieve them with to_block_range and from_block_range functions.
http://www.boost.org/doc/libs/1_46_0/libs/dynamic_bitset/dynamic_bitset.html#to_block_range
(for example, use unsigned char as block type and store them in a stream in binary mode)
Related Questions in C++
- C++ using std::vector across boundaries
- Linked list without struct
- Connecting Signal QML to C++ (Qt5)
- how to get the reference of struct soap inherited in C++ Proxy/Service class
- Why we can't assign value to pointer
- Conversion of objects in c++
- shared_ptr: "is not a type" error
- C++ template using pointer and non pointer arguments in a QVector
- C++ SFML 2.2 vectors
- Lifetime of temporary objects
- I want to be able to use 4 different variables in a select statement in c ++
- segmentation fault: 11, extracting data in vector
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- How can I print all the values in this linked list inside a hash table?
- Configured TTL for A record(s) backing CNAME records
Related Questions in IOSTREAM
- what is the difference between binary and txt modes in C++
- Why two EOF needed as input?
- trying to implement simple ostream singleton class
- How to update data at a particular line in a file?
- function return ostream with precision
- Can't get fstream to seekg back to 0 after EOF flag set
- How to print "\a" in c++ using codelite?
- Capturing and raising events on std::cout flush events
- Is there a way to block cin input for a certain time and then allow input again?
- Bjarne Stroustrup chapter 10.5 example
- Can the C++ Keywords be used with just only the iostream include directive? What else is there besides keywords that can be used with only iostream?
- error: no match for operator>>
- iostream file not found
- How to compose a string and an int to a string?
- Cin not waiting for input despite cin.ignore()
Related Questions in BITSET
- Java BitSet wrong conversion from/to byte array
- c++ - arbitrary void* chunk to bitset
- Manipulating bitset in C++
- convert vector of uint8_t to bitset
- BitSet using more memory than it should
- Memory - Natural address boundary
- Which datastructure to use in big values?
- can java.util.BitSet hold more than MAX_INT no. of bits?
- clear all the multiples of a index in a bitset in Java?
- c++ bitset not inlined?
- Generating sequential numbers using BitSet
- Can you get a set of consecutive bits set in Java Bitset?
- initiate bitset with an integer declared in my function in c++
- add 1 to a bitset of 32 bits
- Java: Count number of bits set in a java.util.BitSet
Related Questions in COMPRESSION
- How to use deflate/inflate SetDictionary with raw deflate/inflate?
- C# How to get file/ copy file from a bzip2 (.bz2) file without extracting the file
- How can I compress four floats into a string?
- Create ZIP File Then Send to Client
- compress json data from rest node.js use express compression
- Advanced Data Compression
- Tools to minify CDD and JS files
- How to use multiple threads for zlib compression (same input source)
- Data compression in RDBMS like Oracle, MySQL etc
- Haskell - Lempel-Ziv 78 Compression - very slow, why?
- Python: how to create tar file and compress it on the fly with external module, using different compression methods not available in tarfile module?
- Why isn't lossless compression automatic on computers?
- PHP Image Compression Before Upload
- Compression of char size integer by removing leading zeroes
- BMP Image Compression and Decompression in java
Related Questions in LOSSLESS-COMPRESSION
- Will Serialization Help in Storing a Huffman Tree To A File
- Is there a utility for estimating a file's size after compression?
- Can anyone make heads or tales of this spigot algorithm code Pitiny.c
- Decode lossless predictive coding
- What is the best lossless compression algorithm for random data
- record 120 sec video and want to reduce size up to 3-4 MB in Android
- Save space writing bitset to a file in C++
- How to achieve minimum size when compressing small amount of data lossless?
- Which deflate (zip) algorithm characteristics can cause a 50% compression factor on the recompression of certain data?
- Optimize images - Losslessly compress images in php
- Compression algorithms for nearly uniform data
- dealing with ljpeg (lossless jpeg) using matlab
- LZ4 match search algorithm (fast scan)
- How do I set up CloudLab for a Simple Experiment?
- Library for further (lossless) Jpeg-compression
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If you normally write one byte per bit in the bitset, then yes, storing eight elements to a byte will save you 7/8 of the space in the limit (you will have to store the size of the bitset somewhere, of course).
For example, this writes a
bitsetusing one character per bit (7/8 overhead):while this stores it optimally compact (if we disregard padding at the end):
Note that
uint8_tis not standard C++03. It resides in C99's<stdint.h>or C++0x's<cstdint>. You can also use anstd::bitset<8>if you want.