Re: Multiple instances of a single DLL

Tech-Archive recommends: Fix windows errors by optimizing your registry




"Serge Wautier" <serge@xxxxxxxxxxxxxxxxxx> wrote in message
news:%23c9yN5GTIHA.5288@xxxxxxxxxxxxxxxxxxxxxxx
Stefan, Nikolaos,

Thanks for your replies.

Yes, my dll contains global data, which is the root of my problem.
Sorry, I should have been more specific about it.

I initially ruled out TLS for a reason that I now realize was stupid. I'll
investigate that route.

Do you have the DLL source code? If so, eliminate your global variables by
moving them into a "context" struct which the caller must provide.

If you don't have the DLL source code, then you basically will require a
separate process to host each instance of the DLL, it's the only way (short
of creating a custom loader that processes fixups) for the data addresses
placed in the code by the compiler to refer to different instances, because
each process gets its own page table. TLS wouldn't help you.

I don't think TLS is appropriate for your problem. Sounds reminiscent of
"When all you have is a hammer everything looks like a nail".


.



Relevant Pages

  • Re: Multiple instances of a single DLL
    ... Yes, my dll contains global data, which is the root of my problem. ... I initially ruled out TLS for a reason that I now realize was stupid. ... If you don't have the DLL source code, then you basically will require a separate process to host each instance of the DLL, it's the only way for the data addresses placed in the code by the compiler to refer to different instances, because each process gets its own page table. ... His original post detailed a single process with multiple threads, each of which had its own copy of certain global variables, which is exactly what TLS is. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Probleme mit __declspec(thread)
    ... Statically declared TLS data objects can be used only in statically loaded ... This fact makes it unreliable to use static TLS data in a DLL ...
    (microsoft.public.de.vc)
  • Re: Multiple instances of a single DLL
    ... Yes, my dll contains global data, which is the root of my problem. ... I initially ruled out TLS for a reason that I now realize was stupid. ... Do you have the DLL source code? ... it's much better to export loose functions and pass the context parameter ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Multiple instances of a single DLL
    ... In fact I myself use TLS all over the place in my code. ... mentioned that might even turn out be more problematic: Renaming the DLLs will lead to excessive collisions of the DLLs preferred load address, so with each DLL instance, not only data, but also the code will have to be duplicated in the processes virtual address space. ... This way a single thread can even work with multiple instances of what was before the per-DLL-global data, ... It always boils down to the question whether you want to have implicit state that the DLL's code deals with and several popular libraries go exactly the way Ben proposed, e.g. JPEGLib and zlib com to my mind. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Multiple instances of a single DLL
    ... Yes, my dll contains global data, which is the root of my problem. ... I initially ruled out TLS for a reason that I now realize was stupid. ... If you don't have the DLL source code, then you basically will require a separate process to host each instance of the DLL, it's the only way for the data addresses placed in the code by the compiler to refer to different instances, because each process gets its own page table. ...
    (microsoft.public.win32.programmer.kernel)