I am wondering why so many examples read byte arrays into streams in cartridges, and not all at once ... I know this is a soft question, but I'm interested.
I understand a little that the equipment and fill buffers can be very size dependent, and you wonβt want to write to the buffer again until it is flushed to where it needs to go, etc .... but with .Net platform (and other modern languages) I see examples of both. So when do you use when and when, or the second absolute, no?
Here is the thing (code) that I mean:
var buffer = new byte[4096]; while (true) { var read = this.InputStream.Read(buffer, 0, buffer.Length); if (read == 0) break; OutputStream.Write(buffer, 0, read); }
but not:
var buffer = new byte[InputStream.Length]; var read = this.InputStream.Read(buffer, 0, buffer.Length); OutputStream.Write(buffer, 0, read);
I believe both are legal? So, why go through the whole bustle of the while loop (in which would you decide to structure it)?
I play devil's advocates here because I want to study the way I can :)
source share