By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,077 Members | 2,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,077 IT Pros & Developers. It's quick & easy.

is MS newer <iostream> is slower than older <iostream.h>?

P: n/a
ai
Hi ,

I have an application which has to read files of size few mba nd read
them into array . Since i am using STL and std namespace to avoid the
error
error C2872: 'ifstream' : ambiguous symbol

when i include <iostream.h> with std namespace and <List>

however the new <iostream> library seems to be atleast 20-25 slower
than <isotream.h> .

any ideas?how i can use old <iostream.h> with STL?
thanks in advance
Giri

Jul 22 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a

"ai@work" <tg*******@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi ,

I have an application which has to read files of size few mba nd read
them into array . Since i am using STL and std namespace to avoid the
error
error C2872: 'ifstream' : ambiguous symbol

when i include <iostream.h> with std namespace and <List>

however the new <iostream> library seems to be atleast 20-25 slower
than <isotream.h> .

any ideas?how i can use old <iostream.h> with STL?


<iostream.h> is not and has never been part of ISO standard
C++, which is the only topic here. If you want to learn
more details about the Microsoft compiler and how to make
it do what you want, try a Microsoft group. The C++ language
makes no requirements about execution speed.

-Mike
Jul 22 '05 #2

P: n/a
* ai@work:

I have an application which has to read files of size few mba nd read
them into array . Since i am using STL and std namespace to avoid the
error
error C2872: 'ifstream' : ambiguous symbol

when i include <iostream.h> with std namespace and <List>

however the new <iostream> library seems to be atleast 20-25 slower
than <isotream.h> .
Some measurements were published in DDJ (or perhaps it was CUJ)
a year or two or three ago, and you're right: in general, no matter
which C++ implementation, the pre-standard iostreams <iostream.h>
are much faster than <iostream>; then again, C library i/o is much
faster than iostreams; and native OS i/o is much faster yet (here
we may be talking orders of magnitude, not just a trivial factor of
2 or something).

any ideas?how i can use old <iostream.h> with STL?


In general you can't, because the pre-standard iostreams _were_
what we had before the standard, so in contrast to other libraries
they are very likely to conflict at some basic level with use of
the real standard library, e.g., tool assumptions.

Consider using _anything_ other than iostreams for serious work.
Or, if you feel adventurous, check out YASLI, the not-quite-mythical
efficient standard library implementation that Andrei may or may
not be the secret mastermind of. I haven't checked that, yet... ;-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #3

P: n/a
ai@work wrote:
Hi ,

I have an application which has to read files of size few mba nd read
them into array . Since i am using STL and std namespace to avoid the
error however the new <iostream> library seems to be atleast 20-25 slower
than <isotream.h> .


Could you post the part of your code which reads the file into an array? I'm
interested to see what kind of code yields these performance differences.

Jonathan

Jul 22 '05 #4

P: n/a
ai
Thanks everyone for their wonderful inputs. As Mr Alf P. Steinbach
pointed out I used stdio.h and it turned out to be faster than
iostream.h .

The code i used is

#include<iostream.h>
ifstream os("filename.txt");
for( i=o;i < lines;i++)
os>>variable;

The problem was if i change #include<iostream.h> to #include<iostream>
it runs very slow on MS . However linux i dont see much change .

Jul 22 '05 #5

P: n/a
ai@work wrote:
Thanks everyone for their wonderful inputs. As Mr Alf P. Steinbach
pointed out I used stdio.h and it turned out to be faster than
iostream.h .

The code i used is

#include<iostream.h>
ifstream os("filename.txt");
for( i=o;i < lines;i++)
os>>variable;

The problem was if i change #include<iostream.h> to #include<iostream>
it runs very slow on MS . However linux i dont see much change .


I don't quite understand your code, because it seems to be reading each
character from the file into the same variable.

In general, if you don't need to take advantage of formatting, you should use
the unformatted input functions of ifstream, or switch to filebuf. E.g.,

char buf[N];
ifstream is("filename.txt", ios::in, ios::binary);
streamsize amt = is.read(buf, N);

Or

char buf[N];
filebuf fb;
fb.open("filename.txt", ios::in, ios::binary);
streamsize amt = is.sgetn(buf, N);

I'd be surpised if using <iostream.h> or <cstdio> performed noticeably better.

Jonathan
Jul 22 '05 #6

P: n/a
Jonathan Turkanis wrote:

Some typos:
ifstream is("filename.txt", ios::in, ios::binary); fb.open("filename.txt", ios::in, ios::binary);
The second comma on each line above should be a bitwise OR.
Jonathan

Jul 22 '05 #7

P: n/a
ai
I'm sorry for the incomplete code. I am reading the whole file (abt a
million lines)into an list of class.

The actual code now is .(which is much much faster than prevous by
order of 20 -25)

while ((!fp == NULL) && (count_profs < MAX_PRO_DIM))
{

fscanf(fp ,"%d %d %d",&len,&lindex,&loffset);

if (!len) break;
hi=hash(loffset);
temp.set ( count_dims , lindex ,loffset,len);
buckets[hi].profiles.push_back (temp);
count_profs ++;
buckets[hi].count ++;
len = 0;
}

previous code was

while ((!os.eof()) && (count_profs < MAX_PRO_DIM))
{
os>>len>>lindex>>loffset;
if (!len) break;
hi=hash(loffset);
temp.set ( count_dims , lindex ,loffset,len);
buckets[hi].profiles.push_back (temp);
count_profs ++;
buckets[hi].count ++;
len = 0;
}

Jul 22 '05 #8

P: n/a
ai@work wrote:
I'm sorry for the incomplete code. I am reading the whole file (abt a
million lines)into an list of class.

The actual code now is .(which is much much faster than prevous by
order of 20 -25)


How do you open the file in the iostreams code? 20-25 sounds too great a
difference to me, unless you are doing something wrong (or the library
has a buffering bug, such as the VC6 one).

Also, why is your input stream called os?

Tom
Jul 22 '05 #9

P: n/a
ai@work wrote:
Thanks everyone for their wonderful inputs. As Mr Alf P. Steinbach
pointed out I used stdio.h and it turned out to be faster than
iostream.h .


Are you running in release mode? Timings of Visual Studio (and many
other compilers) are useless in debug mode because a substantial amount
of optimization, especially the inlining of small functions inside the
library function implementations is disabled.
Jul 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.