some questions from a beginner

  • Thread starter Thread starter Wael
  • Start date Start date
W

Wael

Hi there,

I have some varient questions, and sorry in advance for my novicity..

A- I once had a situation where I had to use an integer type as key in a
hashtable. I knew that would involve boxing. The software engineer at my
office adviced me to solve this by using (int.ToString()) caliming that
would eliminate the boxing under the hood. Is that true?

B- I read once about generics coming in the next .Net version. Are they
going to be optimized for value-typed collections as well?

C- If i have 2 applications referencing the same dll. How can I prevent the
dll from being reloaded for each application? Can it be reusable from
multiple applications? Can I control this usability behavior for each
application? Please I need detailed explanations, if there are articles out
there that would be great. I already read about domain neutral assemblies
but can't get it understood.

D- What about static variables, if I had the same assembly loaded for both
applications? Can I control that behavior, too?

I hope I made myself clear...
 
A - Yes it does. But adding int.ToString() would result in a method
call and a new string object. I don't know if the boxing overhead is
more than those two.
B - Generics in collections are used to avoid boxing, you can have a
List<int>, for instance, which stores integers without boxing. So yes,
using value types with generic collections will make things more
efficient.
C - AFAIK, Windows loads DLL code only once into memory after which it
will be shared by other processes. If you are talking about .NET
assemblies, they are "loaded" once for each appdomain, unless they are
domain neutral. For domain neutral assemblies, the types in those
assemblies will get loaded only once, however each appdomain operates
on its own copy of the static data.

D - AFAIK, you can't share static data between appdomains, even if the
assembly containing the static data is domain neutral.

Regards
Senthil
 
sadhu said:
A - Yes it does. But adding int.ToString() would result in a method
call and a new string object. I don't know if the boxing overhead is
more than those two.

I reckon doing ToString() would result in *much* worse performance. However,
it would almost certainly be undetectable unless it is in a highly
speed-critical part of a highly speed-critical application.

http://c2.com/cgi/wiki?PrematureOptimization
 
Back
Top