Dumb question about array allocation
Posted on 2006-10-19
Dumb question. So the following code (lifted from msdn):
Dim binWriter As New BinaryWriter(New MemoryStream())
Dim binReader As New BinaryReader(binWriter.BaseStream)
Dim verifyArray() As Byte = binReader.ReadBytes(dataArray.Length)
will allocate the verifyArray to the correct size for me? And as long as verifyArray is in scope, the data will still be there?
And if I called verifyArray = binReader.ReadBytes again, it would replace the old array with the new data, and the old array would eventually be garbage collected?
If so, it seems like a strange departure (from the pre-.NET world) for a called function to allocate the array for you, right? What's the rhyme/reason for that?