Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / February 2004

Tip: Looking for answers? Try searching our database.

memory location of static variables?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fuzzy - 19 Jan 2004 05:51 GMT
Does anyone have any insight into how .NET physically stores static
variables?

In a performance critical section of my application, I'm considering
caching some often calculated values where there is a high probability
of input values remaining the same between successive calls.

The cost of recaluation is not huge, but it would be quicker to check
if current input value is the same as the previous input value - if
so, just return previous calculated value.

However, I would have to store these previous values in a static
member variable.  If this caused a processor cache miss or soft page
fault, it would obviously be faster to just recalculate the return
value.
David Notario [MSFT] - 20 Jan 2004 07:20 GMT
The best answer, as always, is to measure.

In released x86 versions of the CLR, normal statics (ie, per appdomain
statics) are stored in a fixed block of memory that the code can directly
reference, so retrieving them is one instruction (mov [address]) for
primitive types and 2 instructions for GC and valuetypes (valuetypes are
stored in boxed form).

For appdomain shared code (ASP.NET), static access is slower, as we have to
get to this statics block via an appdomain based indirection.

Signature

David Notario
Software Design Engineer, CLR JIT Compiler
http://devdiary.xplsv.com

> Does anyone have any insight into how .NET physically stores static
> variables?
[quoted text clipped - 11 lines]
> fault, it would obviously be faster to just recalculate the return
> value.
Dmitry Kostenko - 10 Feb 2004 17:06 GMT
Does this 'per AppDomain indirection' work if use two AppDomains in Windows Forms application and use LoaderOptimization.SingleDomain
Does this indirection work is there are no shared assemblies among domains (except corlib)?
Ori Gershony [MSFT] - 20 Feb 2004 22:33 GMT
This optimization applies only when we don't generate domain neutral code
(i.e. code that can be used in multiple appdomains).  When we generate
domain neutral code, the same code needs to execute in multiple appdomains,
which means that the specific statics that it accesses can be different
depending on the appdomain that it executing in.

When using LoaderOptimization.SingleDomain, the CLR will JIT multiple
copies of the code, and so each one will be optimized for the static
accesses of its specific appdomain.  Ofcourse the cost you are trading off
here is having multiple copies of the code.

As with anything else, I encourage you to measure your specific scenarios
to understand the sources of overhead and areas to focus on.

-- Ori.

--------------------
>Thread-Topic: memory location of static variables?
>thread-index: AcPv+Cy0jbqI3CiaQHSqrn+dm9W+Ug==
>X-Tomcat-NG: microsoft.public.dotnet.framework.performance
>From: =?Utf-8?B?RG1pdHJ5IEtvc3Rlbmtv?=
<anonymous@discussions.microsoft.com>
>References:  <9527b23b.0401182151.7a3dd145@posting.google.com>
<#0btnXy3DHA.3416@tk2msftngp13.phx.gbl>
>Subject: Re: memory location of static variables?
>Date: Tue, 10 Feb 2004 09:06:07 -0800
[quoted text clipped - 12 lines]
>Path: cpmsftngxa07.phx.gbl
>Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.performance:6615
>NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
>X-Tomcat-NG: microsoft.public.dotnet.framework.performance
>
>Does this 'per AppDomain indirection' work if use two AppDomains in Windows Forms application and use LoaderOptimization.SingleDomain?
Does this indirection work is there are no shared assemblies among domains
(except corlib)?

Signature

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note:  For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.