DLL size in memory and hard disk size

Is there a relationship between the size of the DLL in memory and the size on the hard drive?

This is because I use the Task Manager (MS) extension, and I can go to the EXE in the list and right-click β†’ Module, after which I can see all the DLLs that this EXE uses. It has a Length column, but is it in bytes? And the value (Length) of the DLL seems to be different from the size (DLL) on the hard drive. Why?

+6
source share
5 answers

There is a relationship there, but it’s not quite direct or direct.

When your DLL is first used, it maps to memory. This does not load it into memory, it simply allocates some address space in your process where it can / can be loaded if necessary. Then, individual DLL pages are loaded into memory via paging on demand, i.e. When you refer to some address space that has been allocated, the code (or data) will be loaded, associated with this / this address (addresses) if it is not already in memory.

Address mapping now takes up little space (one 4K page for every megabyte of address space that is displayed). Of course, when you load some data into memory, it also uses memory.

Please note, however, that most pages can / will be shared between processes, so if your DLL has been used by 5 different processes at the same time, it will be displayed 5 times (i.e. once for each process it uses), but in memory there will still be only one physical copy (at least usually).

Between them, it can be a little difficult to even determine exactly what you mean by memory consumption of a particular DLL.

+5
source

In determining the size of the dll in memory, two parts are used:

  • As everyone else pointed out, the dll gets a memory card, this leads to the fact that the size is aligned on the pages (for reasons for which the preferred download addresses from the back of the day should be aligned on the page). as a rule, page alignment is 4 Kbit for 32-bit systems, 8 Kbit for 64-bit systems (for a deeper look at this on windows, see this ).
  • The dll contains a segment for uninitialized data, on a disk this segment is compressed, as a rule, to the size of the base +, when the DLL is loaded and initialized, the space for the .bss segment gets allocated, increasing its size. This is usually small and will be ignored by page alignment, but if the dll contains huge static buffers, it can fill the virtual size.
+2
source

Do not think of .dll or .exe as being copied to memory that needs to be executed.

Think of it as a set of instructions for the bootloader. Of course, it contains program text and static data. More importantly, it contains all the information that allows you to transfer text, as well as connect all of its unsatisfied links and export links that may be needed for other modules.

Then, if there is a character and line number for debugging, this is even more text.

Thus, in the general case, you expect it to be larger than the memory image.

+1
source

It all depends on what you call "memory" and what exactly the extension of your TaskManager shows.

Each executable module (Exe / Dll) is mapped to the address space. The size of this display is equal to its size. And, I think, this is what your "extension" shows you.

0
source

The amount of memory will usually be larger than the size of the disk, because when it is mapped to memory, it is aligned on the page. The standard page sizes are 4 KB and 8 KB, so if your DLL is 1 KB of code, it is still going to use 4 KB in memory.

0
source

Source: https://habr.com/ru/post/911044/


All Articles