Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Connecting File Streams

Reply
Thread Tools

Connecting File Streams

 
 
woessner@gmail.com
Guest
Posts: n/a
 
      01-17-2007
This is not a really well-formed question so please bear with me.

I have a very large binary file (tens of GB). I would like to write a
quick program to take a contiguous piece of the file and save it to
another file. Conceptually, this is very simple:

Open ifstream
Open ofstream
Seek ifstream to beginning of piece
Read ifstream in to buffer
Write buffer to ofstream

I'm not very familiar with streams, but I think even I could handle
that. My concern is the with the buffer. I'm going to want to copy
far more data than will fit in memory. That means I will have to use a
loop to read and write the data in chunks. OK, that's still not a
problem. But it does raise the question of how big to make the buffer.
My gut instinct tells me to make the buffer as big as possible, but
I'm not really sure.

I'm hoping there's a way to avoid this problem, altogether. Is it
possible to "connect" an ifstream and an ofstream? Conceptually, this
is what I'm after:

Open ifstream
Open ofstream
Connect ifstream to ofstream
Seek ifstream to beginning of piece
Read ifstream (automatically writes to ofstream)

My hope is that the stream classes will allocate whatever buffers they
need and that those buffers will be appropriately sized.

I've looked through the Josuttis book a little bit. I read the section
on connecting streams, but that seems to be for synchronization. Does
anybody know if this is possible (and a good idea)? If not, I'm open
to any other suggestions.

Thanks in advance,
Bill

 
Reply With Quote
 
 
 
 
Yahooooooooo
Guest
Posts: n/a
 
      01-18-2007
streambuf may help to connect these streams

std::streambuf
std::cout.rdbuf



http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> This is not a really well-formed question so please bear with me.
>
> I have a very large binary file (tens of GB). I would like to write a
> quick program to take a contiguous piece of the file and save it to
> another file. Conceptually, this is very simple:
>
> Open ifstream
> Open ofstream
> Seek ifstream to beginning of piece
> Read ifstream in to buffer
> Write buffer to ofstream
>
> I'm not very familiar with streams, but I think even I could handle
> that. My concern is the with the buffer. I'm going to want to copy
> far more data than will fit in memory. That means I will have to use a
> loop to read and write the data in chunks. OK, that's still not a
> problem. But it does raise the question of how big to make the buffer.
> My gut instinct tells me to make the buffer as big as possible, but
> I'm not really sure.
>
> I'm hoping there's a way to avoid this problem, altogether. Is it
> possible to "connect" an ifstream and an ofstream? Conceptually, this
> is what I'm after:
>
> Open ifstream
> Open ofstream
> Connect ifstream to ofstream
> Seek ifstream to beginning of piece
> Read ifstream (automatically writes to ofstream)
>
> My hope is that the stream classes will allocate whatever buffers they
> need and that those buffers will be appropriately sized.
>
> I've looked through the Josuttis book a little bit. I read the section
> on connecting streams, but that seems to be for synchronization. Does
> anybody know if this is possible (and a good idea)? If not, I'm open
> to any other suggestions.
>
> Thanks in advance,
> Bill


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple streams per file Shea Martin Java 4 08-17-2005 07:54 AM
Giving file names to response streams, possible? Paul L ASP .Net 2 04-11-2005 09:24 PM
help with standard streams and the file descriptor Robert Schweikert C++ 1 01-06-2004 04:19 AM
mixing C FILE* and C++ file streams ?? Marc Cromme C++ 1 12-02-2003 01:56 AM
Using file streams in DLL Saulius C++ 3 08-17-2003 08:15 PM



Advertisments