Go: Global variable problem for dynamic link library

Source: Internet
Author: User

Global variable issues for dynamic link libraries

When the dynamic link library is called multiple times externally, will the global variables of the dynamic library itself be reinitialized each time it is called? How does that make me do it every time I invoke a dynamic library from the last state?


The question of whether you scored the same process or a different process is called. If it is a different process, then your dynamic connection library is completely reloaded. Because a dynamic connection library is mapped to the process in which it is called, and different processes have different address spaces, it is not necessary for different processes to call the same DLL, unless you declare variables in the shared data segment so that the variables are shared among different processes.

If you LoadLibrary the same process multiple times, it doesn't have to be reinitialized, in fact windows works like this. He creates a variable for the dynamic connection library to record the number of times the load is LoadLibrary, and in one process each time the reference count is added 1, each time the reference record is FreeLibrary minus 1, and when the count becomes 0 o'clock, Windows completely releases the DLL. This time you load again, then all the initialization work will be done again. If you load a DLL that has already been loaded elsewhere in the program, it is not initialized.

Save status can be saved to a file, saved to the registry, and so on.
Questioner evaluation
Very detailed, thank you! And thanks to other enthusiastic friends ^_^

Go: Global variable problem for dynamic link library

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.