Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dumb question about array allocation

Posted on 2006-10-19
2
Medium Priority
?
200 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 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Screencast - Getting to Know the Pipeline
Suggested Courses

610 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