Re: istream buffering
This is a multi-part message in MIME format.
----------------2115569303808022630
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
On 2010-07-03 14:09:43 +0200, Alf P. Steinbach /Usenet said:
* Philipp Kraus, on 03.07.2010 13:21:
On 2010-07-02 22:30:12 +0200, Kai-Uwe Bux said:
Philipp Kraus wrote:
Hello,
I have a problem to understand stream data. I have one open istream,
which is valid. I would like to read the data from the stream two
times, but I know I can't read the same position twice. Can I copy the
from the stream in a buffer or anything else in which I can read the
data again? I must duplicated the stream content to work with two
seperated (not referenced) copies.
I think, I am not fully grasping your problem. What would be wrong with
something along the following lines:
int i;
some_file >> i;
int j = i;
I need a cross-plattform (I use boost) solutions for this structur
myclass::input( std::istream x) {
std::istream y;
copy(x, y); // -> that's my problem
mynextmethod(x, y);
}
The above is not a structure or anything else. It's syntactically invalid.
Yes, it should be an example for the problem.
x and y must have the same content, but they don't be a reference. The
method "mynextmethod" is declared with:
mynextmethod( std::istream&, std::istream );
Can I call the copy-constructor like std::istream y(x) to copy the data?
No, there is no such.
You /can/ copy your stream to a std::istringstream, but doing that for
a GiB worth of data would be irresponsible.
Copy your stream to a temporary file.
This is a useful idea, but it may be that once the istream contains
very little data and even very many. Is there a possibility to consider
when it pays not to create a temporary file and when?
Thanks
Phil
----------------2115569303808022630
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.54">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 15.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 15.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 12.0px; line-height: 14.0px; font: 12.0px Helvetica; color: #000080}
p.p4 {margin: 0.0px 0.0px 0.0px 24.0px; font: 12.0px Helvetica; color: #008000}
p.p5 {margin: 0.0px 0.0px 0.0px 24.0px; font: 12.0px Helvetica; color: #008000; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 36.0px; font: 12.0px Helvetica; color: #800000}
p.p7 {margin: 0.0px 0.0px 0.0px 36.0px; font: 12.0px Helvetica; color: #800000; min-height: 14.0px}
p.p8 {margin: 0.0px 0.0px 0.0px 48.0px; font: 12.0px Helvetica; color: #000080}
p.p9 {margin: 0.0px 0.0px 0.0px 48.0px; font: 12.0px Helvetica; color: #000080; min-height: 14.0px}
p.p10 {margin: 0.0px 0.0px 0.0px 12.0px; font: 12.0px Helvetica; color: #000080; min-height: 14.0px}
p.p11 {margin: 0.0px 0.0px 0.0px 12.0px; font: 12.0px Helvetica; color: #000080}
p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p13 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Helvetica}
p.p14 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Times}
</style>
</head>
<body>
<p class="p1">On 2010-07-03 14:09:43 +0200, Alf P. Steinbach /Usenet said:</p>
<p class="p2"><br></p>
<p class="p3">* Philipp Kraus, on 03.07.2010 13:21:</p>
<p class="p4">On 2010-07-02 22:30:12 +0200, Kai-Uwe Bux said:</p>
<p class="p5"><br></p>
<p class="p6">Philipp Kraus wrote:</p>
<p class="p7"><br></p>
<p class="p8">Hello,</p>
<p class="p9"><br></p>
<p class="p8">I have a problem to understand stream data. I have one open istream,</p>
<p class="p8">which is valid. I would like to read the data from the stream two</p>
<p class="p8">times, but I know I can't read the same position twice. Can I copy the</p>
<p class="p8">from the stream in a buffer or anything else in which I can read the</p>
<p class="p8">data again? I must duplicated the stream content to work with two</p>
<p class="p8">seperated (not referenced) copies.</p>
<p class="p7"><br></p>
<p class="p6">I think, I am not fully grasping your problem. What would be wrong with</p>
<p class="p6">something along the following lines:</p>
<p class="p7"><br></p>
<p class="p6">int i;</p>
<p class="p6">some_file >> i;</p>
<p class="p6">int j = i;</p>
<p class="p10"><br></p>
<p class="p4">I need a cross-plattform (I use boost) solutions for this structur</p>
<p class="p5"><br></p>
<p class="p4">myclass::input( std::istream x) {</p>
<p class="p4">std::istream y;</p>
<p class="p4">copy(x, y); // -> that's my problem</p>
<p class="p5"><br></p>
<p class="p4">mynextmethod(x, y);</p>
<p class="p4">}</p>
<p class="p10"><br></p>
<p class="p11">The above is not a structure or anything else. It's syntactically invalid.</p>
<p class="p12"><br></p>
<p class="p13">Yes, it should be an example for the problem.</p>
<p class="p12"><br></p>
<p class="p4">x and y must have the same content, but they don't be a reference. The</p>
<p class="p4">method "mynextmethod" is declared with:</p>
<p class="p4">mynextmethod( std::istream&, std::istream );</p>
<p class="p5"><br></p>
<p class="p4">Can I call the copy-constructor like std::istream y(x) to copy the data?</p>
<p class="p10"><br></p>
<p class="p11">No, there is no such.</p>
<p class="p10"><br></p>
<p class="p11">You /can/ copy your stream to a std::istringstream, but doing that for a GiB worth of data would be irresponsible.</p>
<p class="p10"><br></p>
<p class="p11">Copy your stream to a temporary file.</p>
<p class="p12"><br></p>
<p class="p14">This is a useful idea, but it may be that once the istream contains very little data and even very many. Is there a possibility to consider when it pays not to create a temporary file and when?</p>
<p class="p12"><br></p>
<p class="p13">Thanks</p>
<p class="p12"><br></p>
<p class="p13">Phil</p>
</body>
</html>
----------------2115569303808022630--