News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DLLs and Virtual Memory

Started by AeroASM, May 12, 2005, 05:42:30 PM

Previous topic - Next topic

AeroASM

"In Windows there is only one copy of a DLL in memory, but Windows through the magic of paging makes it appear that each application has its own copy."

How? I have spent ages trying to figure it out but I can't

pbrennick

Aero,
A dll when loaded by an application is loaded into the flat memory used by the application.  Each applicat:ion loads its own dlls.  There is no paging.

Paul

AeroASM

But isn't the point of a DLL that there is only one copy, shared by all the EXE's?
If not, then what is the point? Why not just use static libraries?

Jibz

The read-only parts of a dll are shared amongst processes. Other parts are copy-on-write so each process gets it's own copy if it modifies the pages.

It's all handled through the memory manager, which translates virtual addresses into physical ones.

Opcode

Quote from: AeroASM on May 12, 2005, 08:34:57 PM
But isn't the point of a DLL that there is only one copy, shared by all the EXE's?
If not, then what is the point? Why not just use static libraries?

Hi AeroASM,

I see that you are very interested in how windows manages the memory
internally.
I really suggest you to read this online book, specially this chapter:
http://www.windowsitlibrary.com/Content/356/04/toc.html

It has the precise answer to your question.

Regards,
Opcode

pbrennick

Aero,
DLLs are shared by processes and if you have loaded an exe as a child, it will access the same DLL because a child uses the same resources as the parent.  We can get the handle of another exe that is not a child and communicate with it but I have never heard of this going any deeper.

Quote
But isn't the point of a DLL that there is only one copy, shared by all the EXE's?
If not, then what is the point? Why not just use static libraries?

Don't confuse system DLLs and user DLLs...

Paul

Gustav

> it will access the same DLL because a child uses the same resources as the parent

I don't aggree. Win32 allows file handles to be inherited, but that is it. Other resources are not shared in Win32 between "child" and "parent". Dll read-only pages may be shared among processes, yes, but that has nothing to do with any child-parent relationship.

hutch--

The loading of a DLL within an applications workspace is not as simple as it sounds because another DLL may have been already loaded at the first DLLs preferred load address. The OS relocates the DLL to another load address so when you have multiple applcations using the same DLL, it may not alway be loaded at the same address in each applcations address space.

In this context the code is not shared but duplicated at another load address.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

I have just found out about the .reloc section and things are making a little bit more sense now; I am going to read Opcode's article.

pbrennick

Gustav,
That portion of my reply, parent-child relationships, was in reference to Applications loaded by the Parent.  In that context, the child inherits from the parent and that is just the way it is.

Sorry I confused you.
Paul

Gustav


Paul,

you didn't confuse me. IMO your statement was wrong and I told you so. But we surely can both live with our opinions.

Jibz

Quote from: pbrennickDLLs are shared by processes and if you have loaded an exe as a child, it will access the same DLL because a child uses the same resources as the parent.

Not sure what you mean by 'same'. The child may get the same DLL files loaded, but it will have it's own 'copy' with sharing as mentioned :U.

Quote from: hutch--In this context the code is not shared but duplicated at another load address.

It should only affect the pages that need relocating.