storing a std::bitset to disk takes up too much memory

146 views Asked by At

I have difficulties finding out why my bitset takes up 29MB of memory when writing it to disk. I.e. the file that is written out is 29MB large. I write out the bitset in the following way:

#include <iostream>
#include <string>
#include <fstream>

int main() {
    std::bitset<29621645> a;
    std::ofstream out;
    out.open("myfile");
    out << a;
    out.close();

    return 0;
}

If I do the following, it shows that the bitset only uses 3702712 bytes:

std::cout << sizeof(a); // outputs 3702712

What am I missing here? It seams like it's using 1 byte for 1 bit. I expected the file to only be of size ~3.7 MB since I want actual 8 bits in a byte.

0

There are 0 answers