Re: Framework 2.0 array redim unsatisfactory performance
- From: "Tom Jastrzebski" <tom@xxxxxxx>
- Date: Sat, 13 Aug 2005 04:23:59 GMT
> Remember List(Of T):
> <quote>
> Implements the System.Collections.Generic.IList<> interface using an array
> whose size is dynamically increased as required
> </quote>
> http://msdn2.microsoft.com/library/6sh2ey19(en-us,vs.80).aspx
>
> Notice "an array whose size is dynamically increased as required" which
> IMHO
> is clearly refers to a single array, its singular.
I see what they say, but if this had been true there would not have been
that much memory deallocated, I think.
Test with List(Of Integer) containing 1 million elements shows that when the
initial capacity is specified 92.6% memory is used by objects. While when
the initial capacity is not specified, as much as 50% of memory gets
deallocated as the List(Of T) grows.
Furthermore, the fact that it is almost exactly 50% makes me thinking that
List(Of T) really copies array to twice bigger when needed - the model using
geometric sum would produce precisely this result.
Tomasz
//C# example
long totalMem0 = Process.GetCurrentProcess().WorkingSet64;
long usedMem0 = GC.GetTotalMemory(true);
int n = 1000000;
List<int> li = new List<int>(n);
for (int i = 0; i < n; i++) {
li.Add(i);
}
long totalMem1 = Process.GetCurrentProcess().WorkingSet64;
long usedMem1 = GC.GetTotalMemory(true);
Debug.WriteLine("% mem used: " + ((double)(usedMem1 - usedMem0)) /
(totalMem1 - totalMem0) * 100);
.
- Follow-Ups:
- Re: Framework 2.0 array redim unsatisfactory performance
- From: Jay B. Harlow [MVP - Outlook]
- 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
- 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
- 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
- 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
- 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
- Re: Framework 2.0 array redim unsatisfactory performance
- From: Jay B. Harlow [MVP - Outlook]
- Framework 2.0 array redim unsatisfactory performance
- Prev by Date: Re: Detecting swipe/ Barcode reader input
- Next by Date: Re: SQL query from ASP page
- 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
|