Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLLs and Static Variables

Status
Not open for further replies.

Captrick458

Programmer
Mar 27, 2005
37
0
0
US
I am from the Unix Environment so have absolutely no experience with Windows and DLLs.

I read somewhere that static variable behave improperly in DLLs because of the shared nature of the DLL. Yet, accroding to Microsoft, each time a process attaches to a DLL, the DLL creates a separate data space.

Imperical testing indicates that static variables regardless of whether defined inside a function or defined at the file level, as well as externals maintain their own version of each variable type. I've only done this with integers, but I assume that the outcome will be the same with other simple as well as complex data types.

If anyone has comments or references on this topic, I would love to hear them.

Thanks in advance, Rick
 
Well, I wouldn't say that "static variables behave improperly in DLLs". They may confuse you. Say, instinctively you'd think that a certain static variable doesn't change within an instance of your app (unless you rewrite it), but in DLL, which could be loaded many times in different processes, those static variables may look like regular variables since each time DLL loads up into process it receives a new set of static variables (unless you put them into shared data section).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top