difference between dynamic link library and static library

This is a discussion on difference between dynamic link library and static library within the C Programming forums, part of the General Programming Boards category; cwr, yes, the shared library is essentially in a read only state. the functions are passed to the application as ...

  1. #16
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    cwr,
    yes, the shared library is essentially in a read only state. the functions are passed to the application as needed, but never returned. [ the library is only altered when it is recompiled, not during use ]
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  2. #17
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    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.

  3. #18
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    [ the library is only altered when it is recompiled, not during use ]
    I think you're getting confused by the dll's image on disk, and it's image in memory. Of course a DLL's disk image can't be altered until it is compiled, but a DLL's memory can be overwritten easily. Not only can you change it's variables, but you can overwrite the export table as well. To the best of my knowledge, there is no part of a DLL's memory that you cannot write to.

  4. #19
    ZuK
    ZuK is offline
    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

  5. #20
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    One of you is talking about the executable code in a dll
    Who is talking about executable code? I thought the OP wanted to know if his dll's data would get corrupted when more than one process links to it. Maybe I misunderstood something here.

Page 2 of 2 FirstFirst 12
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, 06: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, 11: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21