static variable in dynamic library?

  • Thread starter =?ISO-8859-1?Q?Eduardo_Su=E1rez?=
  • Start date
?

=?ISO-8859-1?Q?Eduardo_Su=E1rez?=

Hi,

i have tried to understand how static variables work on a dynamic
library, but there's a point i can't see.

* Is the data segment (where static variables live, please confirm)
copied for every binary that is running linked to the library? This is
what it seems from my own experiments. That is, there is a copy of every
static variable for every binary linked. Then, is it really useful the
library?

* Is there a way to share a static variable between different binaries,
(without using threads, i mean)?

Thanks in advance,
-Eduardo
 
I

istartedi

Eduardo Suárez said:
Hi,

i have tried to understand how static variables work on a dynamic
library, but there's a point i can't see.

* Is the data segment (where static variables live, please confirm)
copied for every binary that is running linked to the library? This is
what it seems from my own experiments. That is, there is a copy of every
static variable for every binary linked. Then, is it really useful the
library?

Let's genuflect to the Topic Police first by saying that AFAIK, this is
off-topic for clc. Now that that's out of the way, yes it's "useful"
because the static variable is still shared by all the *callers* within the
program, and it's still hidden within the module, which is what static is
for. No, it's not shared by all the *binaries*. What you're looking for is
a kind of IPC (InterProcess Communication) which is sadly off-topic here
because the C spec is weak on IPC.
* Is there a way to share a static variable between different binaries,
(without using threads, i mean)?

You'll have to ask in a newsgroup specific to your platform. It sounds like
you're using Windows perhaps? IPC is one of the least satisfying elements
of Windows. I actually saw a job listing where they were looking for
somebody who was "familiar with all the methods for IPC on Windows" and I
was immediately struck with fear, loathing, and no desire to apply.
Thanks in advance,
-Eduardo

--$teve
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top