Buffer size in C
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 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.
Re: Buffer size in C
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.
|All times are GMT +5.5. The time now is 02:52.|