DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 23 Aug 2007 02:45:08 -0700,    posted on: microsoft.public.dotnet.languages.csharp        back       

Thread Index
  1    Francisco
          2    Rick Lones
                 3    Peter Duniho


Efficient Array<> of valuetype entry manipulation   
Hello,

  Is there any code faster than this array position manipulation (some
code omitted for brevity)?:

internal struct TreeNodeTableItem {
  public int a;
  public int b;
  public int c;
  public int d;
  public int e;
}

private System.Collections.Generic.List<TreeNodeTableItem>
_tabularView;

....
_tabularView[i].a=amount1;
_tabularView[i].b=amount2;
_tabularView[i].c=amount3;
_tabularView[i].d=amount4;
_tabularView[i].e=amount5;
....

¿Does anybody how to factorize in a variable (or whatever else)
"_tabularView[i]"?

Thanks in advance
Date:Thu, 23 Aug 2007 02:45:08 -0700   Author:  

Re: Efficient Array<> of valuetype entry manipulation   
Francisco wrote:

> Hello,
> 
>   Is there any code faster than this array position manipulation (some
> code omitted for brevity)?:
> 
> internal struct TreeNodeTableItem {
>   public int a;
>   public int b;
>   public int c;
>   public int d;
>   public int e;
> }
> 
> private System.Collections.Generic.List<TreeNodeTableItem>
> _tabularView;
> 
> ...
> _tabularView[i].a=amount1;
> _tabularView[i].b=amount2;
> _tabularView[i].c=amount3;
> _tabularView[i].d=amount4;
> _tabularView[i].e=amount5;
> ...
> 
> Does anybody how to factorize in a variable (or whatever else)
> "_tabularView[i]"?



TreeNodeTableItem tvi = _tabularView[i];
tvi.a = amount1;
tvi.b = amount2;
.. . . etc.

This saves an indexing step for each structure member access.  Whether it's 
noticeably faster for you depends on your usage, of course.  This looks like a 
pattern that a decent optimizer could recognize and handle for you, though.

HTH,
-rick-
Date:Thu, 23 Aug 2007 06:20:09 -0500   Author:  

Re: Efficient Array<> of valuetype entry manipulation   
Rick Lones wrote:

> TreeNodeTableItem tvi = _tabularView[i];
> tvi.a = amount1;
> tvi.b = amount2;
> .. . . etc.
> 
> This saves an indexing step for each structure member access.  Whether 
> it's noticeably faster for you depends on your usage, of course.  This 
> looks like a pattern that a decent optimizer could recognize and handle 
> for you, though.


Posting late always bites me.  But I think the code you suggested is 
_required_ (sort of), since the List<> type is a struct (value type). 
That is, the indexer returns a copy of the value, not the indexed 
element itself.  So the only way to change the value within the list is 
to initialize an existing value type variable with the desired values, 
and then assign that to the indexed list item.

I wrote "sort of", because if one is overwriting all of the values in 
the struct, obviously there's no point in retrieving the indexed list 
item at the start (as in the assignment in the variable declaration in 
the above code).

The code would make more sense as an _alternative_ rather than a 
requirement if the list type was a class instead of a struct.  Then the 
value being returned by the indexer is the reference to the instance, 
and the instance itself can be modified in-place without having to 
reassign anything back to the list.  And of course in that situation, 
the assignment in the variable declaration is necessary.

Pete
Date:Thu, 23 Aug 2007 04:01:33 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us