Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3302628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:52:18+00:00 2026-05-17T20:52:18+00:00

When using streams, memory consumption is supposed to be the same as the size

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:52:19+00:00Added an answer on May 17, 2026 at 8:52 pm

    I believe it depends on the value of HttpWebRequest.AllowWriteBufferStreaming. If this property is true (which it is by default), the request data is all buffered up until you ask for the response.

    If it’s false, the data can be written to the connection as you write it to the stream.

    Note that in either case, it would be a good idea to dispose of the stream as normal:

    using (Stream requestStream = webRequest.GetRequestStream())
    {
        requestStream.Write(buffer, 0, buffer.Length);
    }
    

    You should also use a using statement for the response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using System.IO.Stream.Read(byte[] buffer, int offset, int count) . Is there an alternative to
I'm detecting @replies in a Twitter stream with the following PHP code using regexes.
I'm reading a file in C++ using streams, specifically, fstream, not ifstream. blah blah
I have a question about using streams in .NET to load files from disk.
How do I go about programmatically creating audio streams using Cocoa on the Mac.
One of the things that always bugs me about using Readers and Streams in
I would like to be able to control a flash movie stream using JavaScript
I'm using the StAX event based API's to modify an XML stream. The stream
I'm using an istream which could be stringstream, ifstream or a user-defined stream type
When viewing images my application hums along nicely with low memory consumption, once I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.