Re: dll memory management

From: Michael Brown (see_at_signature.below)
Date: 09/24/04


Date: Fri, 24 Sep 2004 22:32:02 +1200

Jean Bambois wrote:
> Hi
>
> I have a simple question :
> if i load dynamically twice the same delphi dll, will the class
> variables have the same values in the two cases ?

How do you mean "load twice"? If you do something like:
  hLib1 := LoadLibrary('mydll.dll');
  hLib2 := LoadLibrary('mydll.dll');

Then you actually only have one instance of the library loaded into memory
(though it has a reference count of two, so you need to call FreeLibrary
twice before it's unloaded). In other words, the library is only loaded
once. However, if you do
  hLib1 := LoadLibrary('mydll.dll');
  FreeLibrary(hLib1);
  hLib2 := LoadLibrary('mydll.dll');
Then there's nothing to say that the second time the library is loaded it
will end up in the same place (or that dynamically allocated data in the
second DLL will be in the same location as the first.

Finally, if two different processes load the DLL, then it's the same as the
second case: all bets are off in terms of where things end up.

[...]

--
Michael Brown
www.emboss.co.nz : OOS/RSI software and more :)
Add michael@ to emboss.co.nz - My inbox is always open


Relevant Pages

  • Re: running a service/driver/application upon startup
    ... debug version of the image is too large to load onto the device. ... I ran dumpbin/exports on the finger dll and saw the required function names: ... > theories as to why it's not getting loaded but just doing 'services load ...
    (microsoft.public.windowsce.embedded)
  • Re: Unable to load custom driver on WinCE 6
    ... I'm trying to make and load a simple DLL on WinCE 6 by following the ... I've made a subproject at PB project to include the simple DLL ... At the target device, the mydriver.dll file is in the Windows ... I wrote a simple application to load the driver dynamically ...
    (microsoft.public.windowsce.embedded)
  • Re: Cannot activate sbcl
    ... but I think what happens is that Windows sees that your executable has a DATA section that might overlap a DLL's address space then it would reallocate that DLL to different address space. ... VirtualAlloc dynamically in your code is that your program and all its ... What can be done here is to have many tiny executables with different BSS sections in them, which then load a bigger executable in the form of a DLL. ...
    (comp.lang.lisp)
  • Re: DLL load should be easy, but errors
    ... But I cant load even the simple DLL I ... Just supply the exe with the path to the DLL I showed. ... foreach (Type typ in types) ... 'typ.GenericParameterAttributes' threw an exception of type ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Loadlibrary returns err.lastdellerror 127
    ... the resulting .exe I load all the dependant DLL's first (there are ... Assuming this is a 'regular' Dll and not an ActiveX Dll. ... you do NOT need to 'load' all the dependant Dlls. ... Actually the declare statements are there as well. ...
    (microsoft.public.vb.general.discussion)