DLLs
3 отговора
158 прегледа
DLLs
Имам няколко въпроса относно DLLs,и всичките произтичащи от следния пасаж.
Every process that loads the DLL maps it into its virtual address space. After the process loads the DLL into its virtual address, it can call
the exported DLL functions.
The system maintains a reference count for each DLL. When a thread loads the DLL, its reference count is incremented by one. When the
process terminates, or when the reference count goes to 0 (run-time dynamic linking only), the DLL is unloaded from the virtual address
space.
Like any other function, an exported DLL function runs in the context of the thread that calls it. Therefore, the following conditions apply:
-The threads of the process that called the DLL can use handles opened by a DLL function. Similarly, handles opened by any thread of
the calling process can be used in the DLL function.
-The DLL uses the stack of the calling thread and the virtual address space of the calling process.
-The DLL allocates memory from the virtual address space of the calling process.
Пътят до пасажа е: Platform SDK->Windows Base Services->Executables->Dynamic-Link Libraries->About Dynamic-Link Libraries.DLLs and Memory Management
Ако два процеса app0 и app1 имат нужда от функциите в dll0,и app0 извика LoadLibrary("dll0") а скоро след това и app1 извика LoadLibrary("dll0") тогава как се зарежда
dll0?В адресното пространство на app0,в адресното пространство и на app0 и на app1 или как?И ако се зарежда само в адресното пространство на app0 какво ще
стане ако app0 завърши преди app1.
Every process that loads the DLL maps it into its virtual address space. After the process loads the DLL into its virtual address, it can call
the exported DLL functions.
The system maintains a reference count for each DLL. When a thread loads the DLL, its reference count is incremented by one. When the
process terminates, or when the reference count goes to 0 (run-time dynamic linking only), the DLL is unloaded from the virtual address
space.
Like any other function, an exported DLL function runs in the context of the thread that calls it. Therefore, the following conditions apply:
-The threads of the process that called the DLL can use handles opened by a DLL function. Similarly, handles opened by any thread of
the calling process can be used in the DLL function.
-The DLL uses the stack of the calling thread and the virtual address space of the calling process.
-The DLL allocates memory from the virtual address space of the calling process.
Пътят до пасажа е: Platform SDK->Windows Base Services->Executables->Dynamic-Link Libraries->About Dynamic-Link Libraries.DLLs and Memory Management
Ако два процеса app0 и app1 имат нужда от функциите в dll0,и app0 извика LoadLibrary("dll0") а скоро след това и app1 извика LoadLibrary("dll0") тогава как се зарежда
dll0?В адресното пространство на app0,в адресното пространство и на app0 и на app1 или как?И ако се зарежда само в адресното пространство на app0 какво ще
стане ако app0 завърши преди app1.
Re: DLLs
DLL се зарежда в адресното пространство на всеки процес и няма ниакакво значение кой го е заредил първи и кой втори. Вече вътрешно как Windows поддържа мапинга между реалното адресно пространство на където е зареден dll и виртуалното адресно пространство на всеки процес е друго нещо. И това е последното нещо за което трябва да се притесняваш.

Re: DLLs
Работата е там,че продължавам да мисля,че Windows 2000(Windows изобщо) зарежда само едно копие на DLL в паметта.Първият процес заредил DLL "X" го получава в адресно то си пространство.А всеки следващ получава само мамипулатор към DLL "X" с който да се добере до заветните адреси на функциите.Само за глобалните променливи на DLL "X" Windows 2000(Windows изобщо) прави отделно копие за всеки процес в неговото си адресно въображаемо пространство.От твойте думи излиза,че kernel32.dll user32.dll gdi32.dll се зареждат по един път за всеки процес поискал техни функции,това ми се струва лишено от здрав смисъл(отде толкова излишна памет(виж размера на библиотеките)).От друга страна OS поддържа една променлива за DLL "X" която се увеличава с 1 всеки път когато се извика LoadLibrary() и намалява с 1 когато се извика FreeLibrary(),това струва ми се идва да каже,че DLL "X" се зарежда в паметта само веднъж.Но ако това е вярно какво ще стане когато app0 завърши и защо след това с app1 всичко протича гладко.
Re: DLLs
виж сега, това, че даден .dll е зареден във адресното пространство на два различни процеса (може дори на различни адреси за всеки процес), не изключва възможността той да се намира ФИЗИЧЕСКИ на едно и също място, т.е. памет не се губи, точно за това е и reference counter-а.
Пламен
Пламен