Solved

Dumb question about array allocation

Posted on 2006-10-19
2
195 Views
Last Modified: 2010-04-23

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?
0
Comment
Question by:riceman0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17771631
That's correct.

I don't see this as any different from VB6.

Take the Split() function for example:

    Dim data As String
    Dim myArray() As String
   
    data = "1,2,3,4"
    myArray = Split(data, ",")
    Debug.Print LBound(myArray) & " --> " & UBound(myArray)

It automatically allocated the array to the right size for us...
0
 

Author Comment

by:riceman0
ID: 17771756

Hmm, that's true.  Thanks.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question