another .net performance question

  • Thread starter Thread starter C Williams
  • Start date Start date
C

C Williams

Hi.

I have two classes, A and B. A has a public property that returns a
DataTable (an instance variable within the class)

In a class B has a reference to class A. Within a function in class B,
I need to use the datatable from class A. Which of the following is a
better way to do it:

BFunction()
dim tmpTable as DataTable = a.Table
'use variable tmpTable five or six times

BFunction()
'use "a.Table" instead of tmpTable five or six times


Will a.Table and tmpTable point to the same memory, or is a copy made
each time?

Thanks!

-Casey
 
Dim tmpTable as DataTable = a.Table
These point to the same memory location. You would have to look at the IL
to see if you are saving any level of redirection by making a reference
variable to the table. I believe this is the same idea as using the With
clause.

This has no performance bonus.
With a
'Work with .Table 5 times
End with

This has a performance bonus.
With Something.a
'Work with .Table 5 times
End with

So if you were doing
Dim tmpTable as DataTable = Something.a.Table
You would see a difference, but otherwise, no...

Hope it helps
Chris
 
Thanks, Chris!

Chris said:
Dim tmpTable as DataTable = a.Table
These point to the same memory location. You would have to look at the IL
to see if you are saving any level of redirection by making a reference
variable to the table. I believe this is the same idea as using the With
clause.

This has no performance bonus.
With a
'Work with .Table 5 times
End with

This has a performance bonus.
With Something.a
'Work with .Table 5 times
End with

So if you were doing
Dim tmpTable as DataTable = Something.a.Table
You would see a difference, but otherwise, no...

Hope it helps
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top