If I have a global variable defined in a DLL that my application load, is this variable is located at the same memory region that my others global variable defined in my application (so not directly in the DLL) ?
3 Answers
Global data loaded as part of the EXE and global data loaded as part of the DLL both reside in the virtual memory space of the same process, though in different areas corresponding to the segments defined in those EXE and DLL files. Since they are in the same virtual memory space, code in the DLL can use a pointer to an EXE global that the EXE passes to it, and vice-versa.
The answer is yes. MSDN quote: "Every process that loads the DLL maps it into its virtual address space". Go to this link and you'll find the answer to your doubt. Good luck
-
2This is a misleading. It certainly won't be "at same memory region", it is merely in the same process address space. The answer is no. Commented Apr 9, 2011 at 20:38
-
Your tag indicates C++ but the answer may also be platform/OS dependent. Under windows each process will make a copy of the data. Here's a snippet from the MSDN Run Time Behavior article:
Each time a new process attempts to use the DLL, the operating system creates a separate copy of the DLL's data: this is called process attach.
In a single process global data is well,... global.