none
Who shares the static fields on dll classes? RRS feed

  • Question

  • (Mods, please don't hesitate to move this thread if it should belong somewhere else.)
    I'll try to be clear and concise:
    I am writting a class library (a DLL); and one of its classes needs to have some static fields.
    The behavior seems quite clear when there is a single application using the DLL: the fields will be shared by the whole application.
    But now; since it is a quite wide-purpose library, it might happen that two unrelated applications are using it (probably from two identical, but separate files, but perhaps from the same if it ended up in the GAC): Will these separate applications share the static stuff in the DLL, or will they have separate copies?

    Thanks in advance for any answer.
    Wednesday, September 2, 2009 11:28 AM

Answers

  • Separate copies. Each application gets its own copy of the shared data.
    Mattias, C# MVP
    • Marked as answer by herenvardo Wednesday, September 2, 2009 11:51 AM
    Wednesday, September 2, 2009 11:34 AM
    Moderator
  • The address space (in memory) of all processes is different and independent (even if the processes are identical and share the same libraries). So each process will have its own copy of all shared data (the data will only be shared within the process between say multiple threads).
    • Marked as answer by herenvardo Monday, September 7, 2009 11:17 AM
    Wednesday, September 2, 2009 11:40 AM

All replies

  • Separate copies. Each application gets its own copy of the shared data.
    Mattias, C# MVP
    • Marked as answer by herenvardo Wednesday, September 2, 2009 11:51 AM
    Wednesday, September 2, 2009 11:34 AM
    Moderator
  • The address space (in memory) of all processes is different and independent (even if the processes are identical and share the same libraries). So each process will have its own copy of all shared data (the data will only be shared within the process between say multiple threads).
    • Marked as answer by herenvardo Monday, September 7, 2009 11:17 AM
    Wednesday, September 2, 2009 11:40 AM