Click here to Skip to main content
15,908,775 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: VB and MS Excel Pin
Dalek Dave23-Jun-11 3:39
professionalDalek Dave23-Jun-11 3:39 
GeneralRe: VB and MS Excel Pin
geekgautam23-Jun-11 18:29
geekgautam23-Jun-11 18:29 
GeneralRe: VB and MS Excel Pin
geekgautam4-Jul-11 22:44
geekgautam4-Jul-11 22:44 
AnswerRe: VB and MS Excel Pin
Mycroft Holmes23-Jun-11 22:53
professionalMycroft Holmes23-Jun-11 22:53 
GeneralRe: VB and MS Excel Pin
geekgautam24-Jun-11 8:04
geekgautam24-Jun-11 8:04 
GeneralRe: VB and MS Excel Pin
Dalek Dave26-Jun-11 1:59
professionalDalek Dave26-Jun-11 1:59 
QuestionList(Of Integer) vs. an array (VB.NET 2008) Pin
Steven St. John21-Jun-11 5:45
Steven St. John21-Jun-11 5:45 
AnswerRe: List(Of Integer) vs. an array (VB.NET 2008) => Use List PinPopular
MicroVirus21-Jun-11 7:12
MicroVirus21-Jun-11 7:12 
To be honest you pose some really good questions that really hit the fundamentals of .NET and their language integration. I don't really know enough to fully answer you.

One thing I can tell you though: memory reallocation is a very expensive operation, no matter what the implementation, and thus using constant ReDim's as the data is coming in is a bad idea. Probably 90% of the processing time will then be taken by the ReDim statement(s).
The List(Of T) on the other hand allocates blocks of memory at a time, so only once the block is filled does it reallocate.
I believe, but have no hard proof for this, that the utility classes .NET provides are all quite fast (in .NET relative terms, of course).
Quite possibly, using a similar system of allocated larger blocks at a time and only reallocating when a block is filled yourself with ReDim's could be a bit faster. At the very least, you'll probably avoid some function call overhead.

You've got me curious now Smile | :) I'll look in to it, barring someone else being able to answer these questions before I get time :P

You could also always write your own test where you time both implementations. One test where you ReDim the array and add a random integer constantly, and the other where you use a List(Of Integer) and then checking the runtime of each on, say, 10000 or so iterations.

EDIT 1:
First test is in. Adding 100,000 integers to a list using ReDim's or List with standard capacity:
VB ReDim's: 8919.503 ms
List(Of Integer): 2.0002 ms

So, ReDim-ing as you can see is really a bad idea. I do have to note though that on 10,000 items the time is not noticeable.

EDIT 2:
Included a ReDim mimic version of List(Of T)'s implementation: doubling capacity every time we overflow. The results are in:"
VB ReDim's: 8907.5024 ms
List(Of Integer): 2.0001 ms
VB ReDim with Capacity: 2.0001 ms


The conclusion is: use List(Of Integer). There is no speed difference noticeable (not even in my test) between implementing it yourself. But List(Of T) handles a lot of things for you, has lots of extra functionality, and negates the need for manual array management = double win.

modified on Tuesday, June 21, 2011 2:01 PM

GeneralRe: List(Of Integer) vs. an array (VB.NET 2008) => Use List Pin
Thomas Krojer21-Jun-11 20:46
Thomas Krojer21-Jun-11 20:46 
GeneralRe: List(Of Integer) vs. an array (VB.NET 2008) => Use List Pin
MicroVirus21-Jun-11 22:06
MicroVirus21-Jun-11 22:06 
GeneralRe: List(Of Integer) vs. an array (VB.NET 2008) => Use List Pin
Thomas Krojer22-Jun-11 0:42
Thomas Krojer22-Jun-11 0:42 
JokeRe: List(Of Integer) vs. an array (VB.NET 2008) => Use List Pin
MicroVirus22-Jun-11 1:03
MicroVirus22-Jun-11 1:03 
GeneralRe: List(Of Integer) vs. an array (VB.NET 2008) => Use List Pin
Thomas Krojer22-Jun-11 2:01
Thomas Krojer22-Jun-11 2:01 
GeneralRe: List(Of Integer) vs. an array (VB.NET 2008) => Use List Pin
Steven St. John23-Jun-11 11:40
Steven St. John23-Jun-11 11:40 
AnswerRe: List(Of Integer) vs. an array (VB.NET 2008) Pin
AspDotNetDev23-Jun-11 10:16
protectorAspDotNetDev23-Jun-11 10:16 
GeneralRe: List(Of Integer) vs. an array (VB.NET 2008) Pin
Steven St. John23-Jun-11 11:41
Steven St. John23-Jun-11 11:41 
GeneralRe: List(Of Integer) vs. an array (VB.NET 2008) Pin
AspDotNetDev23-Jun-11 12:04
protectorAspDotNetDev23-Jun-11 12:04 
QuestionRequest Pin
QASKU20-Jun-11 2:18
QASKU20-Jun-11 2:18 
AnswerRe: Request Pin
Dalek Dave20-Jun-11 13:18
professionalDalek Dave20-Jun-11 13:18 
QuestionHow to show alert when new records added to database in windows application??? Pin
Sanjay Tiwari120-Jun-11 0:10
Sanjay Tiwari120-Jun-11 0:10 
AnswerRe: How to show alert when new records added to database in windows application??? Pin
Wayne Gaylard20-Jun-11 2:12
professionalWayne Gaylard20-Jun-11 2:12 
GeneralTimer Pin
David Mujica20-Jun-11 2:45
David Mujica20-Jun-11 2:45 
QuestionUpgrade VB6 Database to VB10 Pin
Garner T19-Jun-11 11:07
Garner T19-Jun-11 11:07 
AnswerRe: Upgrade VB6 Database to VB10 Pin
RobCroll19-Jun-11 21:11
RobCroll19-Jun-11 21:11 
GeneralRe: Upgrade VB6 Database to VB10 Pin
Garner T20-Jun-11 13:14
Garner T20-Jun-11 13:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.