 <p>This is definitely not the best way to do it : in each iteration of the loop, you're allocating a new buffer, bigger than the previous one... this could put a lot of pressure on the GC.</p> <p>If you don't know the total length of the data, you could use a <code>MemoryStream</code> :</p> <pre><code>Private Function ReadFromBuffer(ByVal objReader As NetworkStream) As Byte() Dim intRead As Integer = 1024 Dim byteTempbuffer(1023) As Byte Dim allBytes As New MemoryStream While intRead = 1024 intRead = objReader.Read(byteTempbuffer, 0, 1024) allBytes.Write(byteTempbuffer, 0, intRead) End While Return allBytes.ToArray() End Function </code></pre>