from bool array to binary file?

I was trying to save these huge bool arrays (by huge I mean a little over 16.7 million values) into text files by using stringbuilder to append a string to either 0 for false or 1 for true while iterating through the array - to later load at runtime - and well a problem im seeing is this makes huge txt files, like 16mb if I save it all as one. I couldn’t even open this txt up in notepad (or other programs) and decided to try breaking it up into 8 separate txt files. No joy, those 2mb files still are too much to open and view in notepad… bummer.

So I’m wondering if it’s possible (for performance and filesize purposes) to instead save directly to a binary file (you know just the ones and zeros instead of a huge string of the chars 1 and 0) while I’m in the editor, then load those binary files at runtime.

I’m assuming that doing that would produce smaller files, and improve load time on device. Note that opening/editing in notepad (or anything) is not necessary, that’s just how I realized those files are bloated.

Ideas? Anybody done this “save to binary file, then load at runtime” thing?

Here is how I was saving plain text files:

StringBuilder sB = new StringBuilder;

for(int i = 0; i < 16777216; i++)
if (hugeBoolArray  *== false)*

sB.Append (“0”);
sB.Append (“1”);

File.WriteAllText (filePath + “_file.txt”, sB.ToString ());

You could use a BinaryWriter, which has a Write(bool) method. Check out the docs here.

Now, 16 million bools should be ~2mb (one bit for every bool). You won’t get any lower than that as long as it’s just arbitrary boolean values. You’re getting 8 times that, which is probably because the strings are one byte (8 bits) long.

If Write(bool) still ends you with too much data, you’ll want to convert 8 of the bools at a time to bytes, and use File.WriteAllBytes to write them. That should be guaranteed to work.