(To .Net Develpers and not only) Don't know what to think with byte ordering and similar

V

Vladimir

Can anyone halp me with some questions?
Is there multiplatform standart in binary representation of primitive
datatypes when you writing it through BinaryWriter?

In other words if I write by BinaryWriter for example Int64 or Single, can I
without problem read it by BinaryWriter on platform with different (from
Intel x86) byte order?

If yes, then BinaryWriter and BinaryReader implementation will be different
than in .Net Framework for Windows.
Am I right?

My general problem (as I think) in rashness with data types binary
convertions in .Net Framefork. Using BitConverter class too expensive for
perfomanse :-(. I just don't understend it!!! Why it always returns new
arrays!? Why it can't copy binary types to buffer array? Why I can't see
converting to and from decimal ty bytes? Greate. There is only public
convertion from bytes to decimal, but no public from decimal to bytes (there
is only internal convertion from decimal to bytes and it only can be
accessed by BinaryWriter). Convertion from Guid to bytes exitst, but it
return new array and it's implementation produces new arrays (it uses
BitConverter).

I think that each privitive, elementary and structure type (which potentialy
required often to be stored in files (binary data)) have to have common
design to provide effective that functionality (from binary and to binary).
And it must not depends at platform (in terms processor architecture and
similar).

Please, let this letter to read someone form .Net developer team.
And sorry for my bad English.

I hope I'll see changes in feature version .Net Framework.
 
J

John Saunders

Vladimir said:
Can anyone halp me with some questions?
Is there multiplatform standart in binary representation of primitive
datatypes when you writing it through BinaryWriter?

In other words if I write by BinaryWriter for example Int64 or Single, can I
without problem read it by BinaryWriter on platform with different (from
Intel x86) byte order?

You are correct. BinaryReader and BinaryWriter handle binary representation
for you. You don't have to worry about it. In fact, you should keep in mind
that your managed code is never working with native types at all - it's
working with CLR types. That managed code will likely be JIT-compiled down
to native code which does directly manipulate native types, but you aren't
the one who has to worry about it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top