Thread: difference between dynamic link library and static library

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    So my statement of "the running applications are not capable of writing to the memory that the shared library lives" was actually correct? I'm confused now.
    No. It may be true on linux, but not on Windows. On Windows, you have to use a special compiler directive to make the memory shared. For instance, on MSVC you would do:
    Code:
    int varThatIsNotShared = 0;
    #pragma data_seg(".SHARDAT")
    int someSharedVar = 0;
    #pragma data_seg()
    
    #pragma comment(linker, "-section:.SHARDAT,rws")
    So if a DLL has the above code, and some exported functions to manipulate the two variables, they will behave differently. Let's say application A links to this DLL and increments both variables. If application B links to the DLL and reads the variable's values, he will see varThatIsNotShared = 0, and someSharedVar = 1.

    Note that this shared memory can be written to by every process depending on the parameters passed to -section.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Now I start to understand the whole confusion. One of you is talking about the executable code in a dll, the other one is talking about the dlls- data. So both of you are right and wrong.
    Yes the code of a dll is in memory only once and gets mapped into multiple application's addressspace. And yes usually there is some data area that belongs to the dll to store some dll-private state-info and that is readonly ( or even not accessible at all ) for applications and yes a dll can have some shared data-area as well that is read/writable by multiple applications simultaniously.
    Kurt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  2. C++ runtime, dynamic link, mingw.
    By 39ster in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2007, 12:00 PM
  3. using VC6 link VC7 static lib error
    By George2 in forum C++ Programming
    Replies: 5
    Last Post: 06-29-2006, 10:58 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM