All welcome.

Wrote the algorithm for decrypting the firmware. It seems all is well, but did not take into account the speed of writing to the file. In general, I read four bytes from the firmware, for it is necessary, and after decrypting them, I am writing to a new file. But here's the problem, the firmware weighs ~ 71 MB and writing to the file takes a very long time. How can I optimize for faster recording?

  • 2
    - Show the code. - I understand correctly that the data for the record you build in memory, and only after that dump to disk? - In general, about 100 megabytes of files should be written fairly quickly. Are you sure that the recording takes a long time, and not, for example, your decryption is 4 bytes? - Costantino Rupert
  • I read the original 4 bytes, decrypt it and immediately write it to a new file. - Sharp

1 answer 1

Hey.

Writing and reading from disk in small “portions” entails a large number of API calls, each of which is relatively long. Try to buffer the recording: write 4 bytes to the buffer in memory (for example, 64KB long), and the buffer periodically "dump" to disk. The BufferedStream class can do this automatically, just wrap a FileStream in it.

Addition: And yes, pay attention to the comments and make sure that the problem is purely in the write speed of the finished data.

  • Thanks, I'll try now! :) The decryption speed seems to be normal, for example, 26kb of data is decrypted per second. - Sharp
  • At a decryption speed of 26KB / s, 71MB will theoretically be processed ~ 45 minutes. Are you still sure that the bottleneck is the speed of writing to disk? - eigenein
  • 3
    Try writing to a MemoryStream instead of a disc. If it does not become much faster - the brakes are not in the recording on the disc. - eigenein
  • The entire file is processed in approximately 2 ~ 3 min. Thanks for the tips, now I will try. - Sharp
  • I tried the MemoryStream, it did not get very fast. Perhaps yes, you are right! - Sharp