Re: Framework 2.0 array redim unsatisfactory performance



Tom,
| Does anyone
| have any idea whether this will be addressed in the final release?
No, it will not be addressed per se. As each time you do the ReDim Preserve
a brand new array is defined & every element is copied from the existing
array into the new array!

NOTE: Long in VB. NET is a 640Bit value, I suspect you mean Integer which is
now 32-bit (as compared to VB6's Long which was 32-bit). If you are using
Long thinking you have 32-bit values you are actually copying & using twice
as much memory as you need to!

I would recommend instead of ReDim Preserve, that you consider using
System.Collections.Generic.List(Of T) instead, as it will dynamically
allocate memory on a as needed bases (it starts with a buffer of 16
elements, then doubles it each time it needs more space. The List(Of
T).Count reflects the number of elements currently in the collection, while
List(Of T).Capacity reflects the number of elements that can be in the
collection (in other words the size of the buffer). When Count reaches
Capacity the buffer is increased...


For details on List(Of T) see:
http://msdn2.microsoft.com/library/6sh2ey19(en-us,vs.80).aspx

Something like (from memory):

Dim foos As List(Of Integer)

Dim n As Integer = 100000

For index As Integer = 1 To n
foos.Add(index)
Next

NOTE: In .NET arrays & collections use base 0 indexing instead of base 1
indexing. Which means that foos(0) = 1.

NOTE: The "double the size of the buffer" is the general algorithm that .NET
1.0 & 1.1 use, .NET 2.0 may or may not change the algorithm to increase the
size of the buffer...

Hope this helps
Jay

"Tom Jastrzebski" <tom@xxxxxxx> wrote in message
news:EOTJe.781$FV1.299@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Hello,
|
| I was just testing VB.Net on Framework.Net 2.0 performance when I run into
| the this problem.
| This trivial code attached below executed hundreds, if not thousand times
| faster in VB 6.0 than in .Net environment, under VS 2005 Beta 2. Does
anyone
| have any idea whether this will be addressed in the final release?
|
| Thanks,
| Tomasz
|
| Public Sub Main()
| Dim foos() As Long
|
| Dim n As Long
| n = 100000
| Dim i As Long
| For i = 1 To n
| ReDim Preserve foos(i)
| foos(i) = i
| Next i
| Debug.Print(foos(1000))
| End Sub
|
|


.



Relevant Pages

  • Re: Library Design, f0dders nightmare.
    ... first demo mistake but I suggest to you that a sequence of blunders ... The stack is only used temporarily while creating the argv array. ... in the input buffer. ... so you are not wasting memory. ...
    (alt.lang.asm)
  • Re: Allocating memory for part of a C struct
    ... That wouldn't put a buffer on the managed heap. ... I'm pretty sure you are allowed to use the memory returned by ... footer or some other field when you reference using the array name? ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Building Byte Arrays - Speed
    ... What ArrayList & StringBuilder does is double its buffer each time the ... > simple byte array manipulation. ... > Private Sub TestBuildByteArraySpeed(ByRef timeByteArray As Long, ... > Public Sub New ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to cast a buffer pointer into a byte array
    ... allocates a buffer in memory. ... After filling this buffer (with bitmap ... array ) because this is the type the OCX display control it ... Is there a way to send a pointer to the buffer ...
    (microsoft.public.vb.syntax)
  • Re: return a string
    ... Declare a static array of char in your ... mallocmemory for the string inside your function ... >> provide a way to use an alternative allocation function. ... Pass an already allocated buffer and its size to your function. ...
    (comp.lang.c)