For writing binary code, the trick I found most useful is to save all the binary files as a single array in memory, and then move it to your hard drive. Executing bits at a time or bytes at a time or unsigned long at a time is not as fast as having all the data stored in the array and using one instance of "fwrite ()" to store it on your hard drive.
size_t fwrite (const void * ptr, size_t size, size_t count, stream FILE *);
Link: http://www.cplusplus.com/reference/clibrary/cstdio/fwrite/
In English:
fwrite ([array * of stored data], [size in bytes of the OBJECT array. for unsigned chars → 1, for unsigned long longs → 8], [number of instances in the array], [FILE *])
Always check your results to confirm success!
In addition, an argument can be made that the maximum type of the object should be as large as possible ([unsigned long long]> [char]). Although I do not understand the coding behind "fwrite ()", I believe that the time to convert from the natural object used in your code to [unsigned long long] will take more time in combination with writing than "fwrite ()" for account of what you have.
When I studied Huffman coding, it took me a few hours to realize that there was a difference between [char] and [unsigned char]. Note this method that you should always use unsigned variables to store a clean binary.
Daniel Peirano
source share