1

I have an app that converts binary file into ASCII file. With profiler I found that I spend 25% of time doing Encoding.GetBytes() which is called from BinaryWriter.Write(wchar[]). It is completely correct since I have many constructs similar to this one:

m_writer.Write("some fancy long text".ToCharArray());

Do you have any smart idea how to avoid this encoding conversion?

I now that one idea would be to to do something similar to this:

const byte[] SOME_FANCY_LONG_TEXT = Encoding.ASCII.GetBytes("some fancy ...");
// ... and later
m_writer.Write(SOME_FANCY_LONG_TEXT);

but I have to many such entries to do it manually.

2
  • 1
    Could you please be more specific about "converting binary file into ASCII file" ? What conversion do you apply exactly ? Commented Jul 24, 2009 at 8:02
  • What is the difference between binary file into ASCII file? (what do you mean by that) Commented Jul 25, 2009 at 10:36

1 Answer 1

5

If you're creating a text file, why are you using BinaryWriter at all? Just use a TextWriter. BinaryWriter is meant for binary streams where you want to write primitives, strings etc in a simple way.

(Is all your text definitely going to be ASCII, by the way? You might want to consider using UTF-8 instead.)

Sign up to request clarification or add additional context in comments.

1 Comment

Problem is no longer relevant :) Thanks for input - helped greatly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.