473,394 Members | 1,813 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.

Connecting File Streams

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

Jan 17 '07 #1
1 1942
streambuf may help to connect these streams

std::streambuf
std::cout.rdbuf

wo******@gmail.com 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
Jan 18 '07 #2

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

Similar topics

1
by: Marc Cromme | last post by:
I would like to ask a question about (good ?) style and possibilities in mixing C FILE* and C++ file streams. The background is that I want to use the C libpng library from within C++, but I...
3
by: sb | last post by:
I think streams are nice, but what do you do when you have to write to or, even worse, read from a FILE*, for example a UNIX stream? C++ streams can not be created from FILE*'s or have them...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
2
by: bonk | last post by:
Hello how do I connect streams in c# ? Imagine the followung scenario: I have a StreamWriter that writes Text to a Stream. How can I tell that Stream to pass that Data to another Stream...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
27
by: Jeff | last post by:
Im trying to figure out why I cant read back a binary file correctly. I have the following union: #define BITE_RECORD_LEN 12 typedef union { unsigned char byte; struct { unsigned char type;...
3
by: =?Utf-8?B?TG9yZW4=?= | last post by:
I’m trying to encrypt and decrypt a file in vb.net. I am using the TripleDESCryptoServiceProvider encryption found in System.Security.Cryptography. Below is the code for my Encrypt and Decrypt...
2
by: =?Utf-8?B?QXJ0?= | last post by:
I need to go through a folder and all of its subfolders and collect the Title, Comments, Keywords and a few other items. These are items that you see when you select a file in the Windows explorer...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.