Re: Best practice using large objects in foreach
- From: "Laura T" <laura.t@xxxxxxxxxx>
- Date: Thu, 27 Jul 2006 17:13:24 +0200
I don't see any object reuse, at most variable reuse. Compiler does not care
much about it. Nor does CLR.
From the performance point of view, A & B are the same. C is slower becauseof using().
"Benny" <bennyandlinds@xxxxxxxxx> ha scritto nel messaggio
news:1154011992.988169.191070@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I just wanted to throw the discussion out there on what the best
practice people feel is for using large objects in a foreach loop. For
example if you are reusing an Image object in a loop like this (letters
above snippets are for reference purposes):
A
foreach ( string s in myList )
{
Image img = Image.FromFile( s );
// operate on img
}
would it run more efficiently like this?
B
Image img = null;
foreach ( string s in myList )
{
img = Image.FromFile( s );
// operate on img
}
or
C
foreach ( string s in myList )
{
using ( Image img = Image.FromFile( s );
{
// operate on img
}
}
the list goes on....
Let me know what your thoughts are.
.
- Follow-Ups:
- Re: Best practice using large objects in foreach
- From: Marc Gravell
- Re: Best practice using large objects in foreach
- References:
- Best practice using large objects in foreach
- From: Benny
- Best practice using large objects in foreach
- Prev by Date: Re: Best practice using large objects in foreach
- Next by Date: Re: Best practice using large objects in foreach
- Previous by thread: Re: Best practice using large objects in foreach
- Next by thread: Re: Best practice using large objects in foreach
- Index(es):
Relevant Pages
|
Loading