Board index » cppbuilder » istream, ostream (efficiency memcpy)

istream, ostream (efficiency memcpy)


2004-01-23 03:30:51 PM
cppbuilder42
istream:
1) How do I determine in the most efficent method possible how many bytes
remain in the istream?
2.) If I know the number of bytes remaining in the istream what is the most
efficient way to write these bytes to a byte buffer? Can I use memcpy
somehow?
Currently I have while(!aIstream.eof()) and inside of the loop I read a byte
(unsigned char) and assign it to the correct position in my byte buffer.
This doesn't seem very efficent but it works.
ostream:
1) How do I write count bytes from byte buffer to an ostream efficiently?
Currently I'm looping writing a byte at a time. I suppose I could write
type cast to long doubles and write those out until I need to write 9 or
less bytes...but again I would like to set the size of the inter{*word*7}buffer
of ostream to a count and then use memcpy to copy count bytes from my buffer
to ostream's buffer.
Any help or ideas on efficiency concerning istream and ostream would be much
appreciated.
 
 

Re:istream, ostream (efficiency memcpy)

Hi!
Junk Mail wrote:
Quote
istream:
1) How do I determine in the most efficent method possible how many bytes
remain in the istream?
You can try to seek to the end and determine the difference of tellg()
before and after seeking.
Quote
2.) If I know the number of bytes remaining in the istream what is the most
efficient way to write these bytes to a byte buffer? Can I use memcpy
somehow?
Use basic_istream<>::readsome to read into a buffer. You CANNOT use
memcpy anyhow.
Quote
ostream:
1) How do I write count bytes from byte buffer to an ostream efficiently?
Use basic_ostream<>::write to insert a buffer into the stream.
Quote
but again I would like to set the size of the inter{*word*7}buffer
of ostream to a count and then use memcpy to copy count bytes from my buffer
to ostream's buffer.
Again you CANNOT use memcpy anyhow.
Frank
 

Re:istream, ostream (efficiency memcpy)

"Junk Mail" < XXXX@XXXXX.COM >writes:
Quote
1) How do I determine in the most efficent method possible how many bytes
remain in the istream?
You can't, since there is no such number. Consider std::cin, which is usually
attached to the keyboard. The number of remaining bytes depends on how much
the user is willing to type.
 

{smallsort}