Solved

Dumb question about array allocation

Posted on 2006-10-19
2
189 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
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
Comment Utility

Hmm, that's true.  Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now