Need to convert txt file into binary file in C++

前端 未结 8 881
你的背包
你的背包 2021-01-06 23:32

I have a txt file with numbers like 541399.531 261032.266 16.660 (first line) 541400.288 261032.284 16.642 (2nd line)........hundred of points. i want to convert this file i

8条回答
  •  孤城傲影
    2021-01-07 00:26

    I suggest avoid writing the binary representations to a file for a few hundred or thousand points. This is called a micro optimization and the development time outweighs any gain in performance of the executable.

    Not Worth Saving for Size

    In current computing, most platforms support huge (gigabyte) file sizes and computers have megabytes or gigabytes of memory for programs to use. So writing in binary for saving room (file size or memory size) doesn't gain any significant advantages compared to other bottlenecks in the development cycle.

    Not Much Gain in performance.

    The idea that loading a binary representation from a file is more efficient than translating a textual representation is true. However, most processors can translate an ASCII translation faster than the binary data can be read in. Summary: the time gained by removing the translation is overshadowed by bigger consumers of time such as file I/O, and context switches.

    Reducing usefulness of data

    More applications can process textual representation of floating point numbers than the binary representation. With a textual representation, the data can be easily used in spreadsheets, word processors and analysis tools. Files containing the binary representations require more effort. When was the last time you tried reading a file of binary floating point numbers into a spreadsheet? Don't under estimate the future potential for data files.

    Profile Before Optimizing.

    Changing data representation is a form of optimizing. The rules of optimizing (in order of importance) are:

    1. Don't.
    2. Only if the program doesn't fit on the target machine or Users complain about the speed.
    3. Optimize after the program is robust and runs correctly.
    4. Optimize the platform, if possible, before optimizing the program.
    5. If you need to optimize, Profile first.
    6. Optimize Requirements before optimizing code.
    7. Optimize Design & Algorithms before optimizing code.
    8. Optimize data before optimizing code.
    9. Optimize in high level language before writing in assembly.

提交回复
热议问题