Re: Framework 2.0 array redim unsatisfactory performance
- From: "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@xxxxxxx>
- Date: Tue, 9 Aug 2005 08:07:04 -0500
Tom,
| My tests show that generic based List<> uses at least 5 additional bytes
for
| each entry. Not a surprise, most likely it is implemented as single-linked
| list. In most applications it is not a concern, but in my cases it is.
List(Of T) is implemented as an Array not a single-linked list, per:
http://msdn2.microsoft.com/library/6sh2ey19(en-us,vs.80).aspx
<quote>
Implements the System.Collections.Generic.IList<> interface using an array
whose size is dynamically increased as required.
</quote>
Note it states "using an array whose size is dynamically increased", this is
the double action I was referring to.
How are you determining "at least 5 additional bytes for each entry"?
You are testing against a List(Of Integer) & not List(Of Object) where each
element is being boxed?
Are you looking at the Capacity compared to Count? Capacity needs to be
larger as this is where the performance comes in. Rather then alloc a new
array & copy all the elements for each element added.
Yes there is some overhead as compared to an array, however I would expect
this to be 4 to 12 bytes per instance of List(Of T), not per element.
FWIW: List(Of T) is the generic version of ArrayList. A couple of advantages
of List(Of T) are that it avoids the "boxing penalty" that ArrayList has,
plus it ensures type safety.
Hope this helps
Jay
"Tom Jastrzebski" <tom@xxxxxxx> wrote in message
news:rNVJe.122$O07.93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Jay,
|
|
|
| Whether Integer or Long type is being used of course makes a difference.
| However, my tests show that this difference is not that significant, and
| still old good VB 6.0 performs way better.
|
|
|
| The reason why I test Array is because I need a dynamic data structure
with
| as small memory overhead as possible.
|
| My tests show that generic based List<> uses at least 5 additional bytes
for
| each entry. Not a surprise, most likely it is implemented as single-linked
| list. In most applications it is not a concern, but in my cases it is.
|
|
|
| Since dynamic array is not available in C# I was just wondering how
| efficient this VB structure was before starting thinking about alternative
| approaches using C++.
|
|
|
| Thanks,
|
| Tomasz
|
|
.
- Follow-Ups:
- Re: Framework 2.0 array redim unsatisfactory performance
- From: Tom Jastrzebski
- Re: Framework 2.0 array redim unsatisfactory performance
- References:
- Framework 2.0 array redim unsatisfactory performance
- From: Tom Jastrzebski
- Re: Framework 2.0 array redim unsatisfactory performance
- From: Jay B. Harlow [MVP - Outlook]
- Re: Framework 2.0 array redim unsatisfactory performance
- From: Tom Jastrzebski
- Framework 2.0 array redim unsatisfactory performance
- Prev by Date: Re: Background color of rectangle
- Next by Date: Re: string to string collection
- Previous by thread: Re: Framework 2.0 array redim unsatisfactory performance
- Next by thread: Re: Framework 2.0 array redim unsatisfactory performance
- Index(es):
Relevant Pages
|