unformatted i/o

M

Marc Schellens

What is the common way to do unformatted io
in c++?
That means putting out everything just a a sequence of bytes.
And what is the most efficient way changing the endian while doing
io?
thanks,
marc
 
J

John Harrison

Marc Schellens said:
What is the common way to do unformatted io
in c++?

read and write methods of istream and ostream. Don't forget to open any
files in binary mode.
That means putting out everything just a a sequence of bytes.
And what is the most efficient way changing the endian while doing
io?

Swap the bytes round is the only way. ANY method you pick do to this is
likely to be TONS more efficient than the actual I/O itself, so I wouldn't
worry about efficiency in this case.
thanks,
marc

john
 
T

Thomas Matthews

Marc said:
What is the common way to do unformatted io
in c++?
read and write methods of the streams,
or fread and fwrite. Make sure that the stream or
FILE is opened in binary mode so that no bytes
are translated.

That means putting out everything just a a sequence of bytes.
And what is the most efficient way changing the endian while doing
io?
The most efficient method of changing endianness is to do this
all at once before the I/O is started. For example, to output
ten multi-byte integers:
1. Create a buffer / array to hold the integers.
2. Load the buffer with the data.
3. Change endianess of the data.
4. Write entire buffer with a single call to write() method.

The I/O is most efficient with fewer calls to large chunks of
data than many calls to small sized data. (Although to be
fair, you should make the measurements yourself on your
platform).
thanks,
marc



--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
G

Gianni Mariani

Thomas said:
read and write methods of the streams,
or fread and fwrite. Make sure that the stream or
FILE is opened in binary mode so that no bytes
are translated.



The most efficient method of changing endianness is to do this
all at once before the I/O is started. For example, to output
ten multi-byte integers:
1. Create a buffer / array to hold the integers.
2. Load the buffer with the data.
3. Change endianess of the data.
4. Write entire buffer with a single call to write() method.

The I/O is most efficient with fewer calls to large chunks of
data than many calls to small sized data. (Although to be
fair, you should make the measurements yourself on your
platform).

This thread on google discusses a similar issue - this points to some
ideas with network order.

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&[email protected]
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top