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
Solved

Dumb question about array allocation

Posted on 2006-10-19
2
194 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 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