Archived

This topic is now archived and is closed to further replies.

File Processing - Streams

This topic is 5751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a question... When I create a stream object and "open" a file does that file get stored into memory? Or is the stream simply a buffer of predetermined size and when I want information from that file in memory I read it into the buffer, then I store it in a variable out to memory? So basically does an entire file get put into memory when it is opened for file processing? If not what is occuring... Thanks, Grudgian widmayer@wi.rr.com

Share this post


Link to post
Share on other sites
quote:
Original post by Widmayer
When I create a stream object and "open" a file does that file get stored into memory?

No.

quote:

Or is the stream simply a buffer of predetermined size and when I want information from that file in memory I read it into the buffer, then I store it in a variable out to memory?

In the context of the language you are using it is read into a buffer (variable) that you provide. The OS may do some underlying buffering of the stream, but worrying about that will possibly lead to confusion.

quote:

So basically does an entire file get put into memory when it is opened for file processing? If not what is occuring...

Firstly, the file gets connected to a stream, where a stream is an abstraction of an I/O object. Once that initial connection is made, you can perform several other operations on that stream, depending on the stream''s type. For example, if you have an input file stream (ifstream), you can open and close the stream, and you can read from the stream (amongst other things). When you read from the stream, you read into a variable that you have declared in your code. Don''t worry about buffering concerns unless you need to perform micro-optimisation (which will be rare). If your code depends in some way on OS-level buffering, then you code is inherently non-portable.

Share this post


Link to post
Share on other sites