4

When I load a DLL in program, how does that occur in memory? Does it get loaded into my Virtual Address Space? If it does, where are the text and data segments stored? I have a 32-bit program I'm maintaining, which uses a large part of the available heap for image processing routines, and I want to know how much I should worry about loading DLLs which themselves might use a lot of space.

chrisb2244
  • 2,940
  • 22
  • 44
zero_cool
  • 51
  • 1
  • 5

1 Answers1

2

Yes: everything that your process needs to access must be in its adress space. This applies to your code and to your data as well.

Here you'll find more about the anatomy of process memory and adress space and here it's explained that dll are loaded into the virtual adress space.

Remark: the dll might be shared between several processes: it is then loaded only once in memory by the OS. But every process using it could potentially see it at a different place in its own virtual adress space (see also this SO answer about relative virtual adresses).

Community
  • 1
  • 1
Christophe
  • 68,716
  • 7
  • 72
  • 138
  • So the term "loading a DLL into a process's address space" means physically loading the DLL (if its not already been loaded by another process) and then mapping the physical address of the start of the DLL to the virtual address of the process? And then presumably either all the references in the process to DLL functions have to be patched up (since the linker could not have known where the DLL would be loaded) OR you use GetProcAddress to look them lazily up when they are called. Is that correct? – Motorhead Oct 15 '20 at 03:39
  • That’s the general idea. It depends if it’s load time or run tme dynamic linking (more in the second link provided) – Christophe Oct 15 '20 at 06:01