473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

unformatted i/o

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

Jul 19 '05 #1
3 3314

"Marc Schellens" <m_*********@hotmail.com> wrote in message
news:3F**************@hotmail.com...
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
Jul 19 '05 #2
Marc Schellens wrote:
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

Jul 19 '05 #3
Thomas Matthews wrote:
Marc Schellens wrote:
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).


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

http://groups.google.com/groups?hl=e...concentric.net

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mitch | last post by:
Hi all, I hope this is the right place for this post, apologies if it is not. I am trying to write a program that creates an input file for a dispersion model. The model is expecting a Fortran...
4
by: TheDD | last post by:
Hello all, i'm having a problem with input. My aim is to read a pbm file wich looks like: $ head file.pbm P1 # Created by Paint Shop Pro 7 3510 2550 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
0
by: Eric | last post by:
Visual C++ 2005 Express MVP's and experience programmer's only please!... I need to get the number of lines in a textbox so I can insert them into a listview. The text comes from my database...
3
by: Bob | last post by:
I had an app in VB6 that I'm "upgrading" <GGGG> to Vb.net 2005. In Vb6 I had rtf text in a field in a Sql server 2000 field and it would show up as formatted RTF in my richtextbox. In vs.net that...
1
by: Andrea Gavana | last post by:
Hello NG, that may sound a silly question, but I didn't find anything really clear about the issue of reading unformatted big endian files with Python. What I was doing till now, was using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.