global variables in dynamic libraries

R

Rahul

Hi Everyone,

I have a dll whose methods work in a global variable. The global
variable is declared in a particular source file and the function is
declared in a header file used by the application (exe). Now the exe
loads this dll and invokes the function. The function works on the
global variable and perform necessary operation.

Now the question is, where exactly is the global variable loaded in
the exe? If it is in the data segment, is there a limit to the data
segment or can the data segment grow in size? can i keep on adding
global variables to the dll and expect the exe to work fine?

When is the size to be allocated in the data segment computed (run
time or compile time)? For stack, i know that the size is computed
during the compilation.

Thanks in advance ! ! !
 
A

Alexander Bartolich

Rahul said:
I have a dll whose methods work in a global variable.

Your question is platform specific and hence off-topic.
comp.os.ms-windows.programmer.win32 might be a better suited.
[...]
Now the question is, where exactly is the global variable loaded in
the exe? If it is in the data segment, is there a limit to the data
segment or can the data segment grow in size? can i keep on adding
global variables to the dll and expect the exe to work fine?

Educated guess: every DLL has its own data segment.
 
T

Thomas Zimmermann

Hi
I have a dll

So this is OT, but anyway...
Now the question is, where exactly is the global variable loaded in
the exe?

The data segment of the dll.
can the data segment grow in size?

The size, measured in memory pages, of segments can grow until the
address space is full.
global variables to the dll and expect the exe to work fine?

You can, but shouldn't. Despite problems with the design of your
application, there are some technical issues as well. IIRC Windows
doesn't have position-independent code, i.e., the address of all
variables and functions is fixed. When there is a collision with segments
of other DLLs, the segment has to be copied to another offset. As a
result, the loader walks through all the code and changes all references
to the segment's content. This can take ages.
When is the size to be allocated in the data segment computed (run
time or compile time)? For stack, i know that the size is computed
during the compilation.

The size of a single data segment is known at compile time of the DLL.
The size of all data segments is known at compile time of the EXE.

But the compiler cannot possibly know the stack size, or do you mean the
size of a stack frame?

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top