When using streams, memory consumption is supposed to be the same as the size of the buffer. However, I am not sure how a stream works when I look at the following code, which uses http request and response. (HttpWebRequest to be precise)
Stream requestStream = webRequest.GetRequestStream();
// Here write stuff to the stream, data is a string.
webRequest.ContentLength = data.Length;
byte[] buffer = Encoding.UTF8.GetBytes(data);
// Obtain request stream from request object so I can send data.
requestStream = webRequest.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
WebResponse response = webRequest.GetResponse();
I can keep writing stuff to a requestStream, say in a loop, instead of just writing one string, but none of it will reach the target server until the call to webRequest.GetResponse() is made. Then, how (or where) is the data managed by the stream, before the last line is executed ?