Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does stream mean? What are its characteristics?

C++ and C# both use the word stream to name many classes.

  • C++: iostream, istream, ostream, stringstream, ostream_iterator, istream_iterator...
  • C#: Stream, FileStream,MemoryStream, BufferedStream...

So it made me curious to know, what does stream mean? What are the characteristics of a stream? When can I use this term to name my classes? Is this limited to file I/O classes only?

Interestingly, C doesn’t use this word anywhere, as far as I know.

like image 534
Kashif Avatar asked Feb 28 '11 16:02

Kashif


People also ask

What are the 4 main characteristics of streams?

Rivers are always trying to balance themselves, or, in other words, they are trying to find equilibrium. River equilibrium occurs when four factors are in balance. These factors are sediment discharge, sediment particle size, stream flow, and stream slope.

What are 2 stream characteristics?

Streams have left and right streambanks (looking downstream) and streambeds consisting of mixtures of bedrock, boulders, cobble, gravel, sand, or silt/clay. Other physical characteristics shared by some stream types include pools, riffles, steps, point bars, meanders, floodplains, and terraces.

What it mean to stream?

Streaming refers to any media content – live or recorded – delivered to computers and mobile devices via the internet and played back in real time. Podcasts, webcasts, movies, TV shows and music videos are common forms of streaming content. Modal.


2 Answers

Many data-structures (lists, collections, etc) act as containers - they hold a set of objects. But not a stream; if a list is a bucket, then a stream is a hose. You can pull data from a stream, or push data into a stream - but normally only once and only in one direction (there are exceptions of course). For example, TCP data over a network is a stream; you can send (or receive) chunks of data, but only in connection with the other computer, and usually only once - you can't rewind the Internet.

Streams can also manipulate data passing through them; compression streams, encryption streams, etc. But again - the underlying metaphor here is a hose of data. A file is also generally accessed (at some level) as a stream; you can access blocks of sequential data. Of course, most file systems also provide random access, so streams do offer things like Seek, Position, Length etc - but not all implementations support such. It has no meaning to seek some streams, or get the length of an open socket.

like image 140
Marc Gravell Avatar answered Sep 24 '22 20:09

Marc Gravell


There's a couple different meanings. #1 is what you probably mean, but you might want to look at #2 too.

  1. In the libraries like those you mentioned, a "stream" is just an abstraction for "binary data", that may or may not be random-access (as opposed to data that is continuously generated, such as if you were writing a stream that generated random data), or that may be stored anywhere (in RAM, on the hard disk, over a network, in the user's brain, etc.). They're useful because they let you avoid the details, and write generic code that doesn't care about the particular source of the stream.

  2. As a more general computer science concept, a "stream" is sometimes thought of (loosely) as "finite or infinite amount of data". The concept is a bit difficult to explain without an example, but in functional programming (like in Scheme), you can turn a an object with state into a stateless object, by treating the object's history as a "stream" of changes. (The idea is that an object's state may change over time, but if you treat the object's entire life as a "stream" of changes, the stream as a whole never changes, and you can do functional programming with it.)

like image 32
user541686 Avatar answered Sep 21 '22 20:09

user541686