static variable in dynamic library?

Discussion in 'C Programming' started by =?ISO-8859-1?Q?Eduardo_Su=E1rez?=, Aug 25, 2003.

  1. 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
     
    =?ISO-8859-1?Q?Eduardo_Su=E1rez?=, Aug 25, 2003
    #1
    1. Advertising

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

    istartedi Guest

    Eduardo Suárez <eduardo_at_ctm.ulpgc.es> wrote in message
    news:3f4a46b4$...
    > 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
     
    istartedi, Aug 25, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kookey
    Replies:
    3
    Views:
    20,808
    Andrew Thompson
    Aug 20, 2005
  2. Replies:
    6
    Views:
    884
    red floyd
    May 10, 2005
  3. Replies:
    2
    Views:
    6,604
    Maett
    May 16, 2005
  4. iceColdFire

    Static library Vs. Dynamic library

    iceColdFire, May 17, 2005, in forum: C++
    Replies:
    3
    Views:
    17,120
  5. Even

    static library and dynamic library

    Even, Oct 18, 2007, in forum: C Programming
    Replies:
    6
    Views:
    665
    Mark McIntyre
    Oct 20, 2007
Loading...

Share This Page