Buffer size in C

Discussion in 'C' started by dereliction, Jan 28, 2007.

  1. dereliction

    dereliction New Member

    Joined:
    Jan 28, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    HEllo all,
    I need to declare a buffer that stores an incoming message over the network from a server. The problem is, I dont know the length of this message.
    I declare my buffer as char buf[8192] for example.

    So right now, I read the message until the buffer gets full, and then write the contents of the buffer to a file and so on. There is an I/O involved everytime the buffer gets full.

    What I;d like to do is to have some sort of infinite buffer, that would store all the message. Then I can use just one I/O to write contents of buffer into a file. Is this possible to do? Thanks.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Nope. And there's the same amount of I/O involved, anyway. If you had a 1-byte buffer, there'd be a lot of overhead to the file I/O. If you had a trillion-byte buffer and a trillion-byte message the overhead would be less, but the impact on the system and the message recipient would be unfavorable. For instance, the trillion byte message would lock up the system, preventing other things from being accomplished, until it was all received. A preemptive OS (which you probably have, but scads of systems don't) would just step in and add the overhead anyway, less efficiently and in larger quantities.

    A professional software designer considers the issues and maximizes performance for any given implementation, according to the most reasonable expectation for the size, speed, and accuracy of the communication, and some reasonably defined failure acceptability. That distinguishes them from pure code monkeys and inflates their paycheck.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice