/MT/MD/ml/MTD/MDD/MLD differences

Source: Internet
Author: User
Multithreaded libraries performancethe single-threaded CRT is no longer (in vs2005) available. this topic discusses how to get the maximum performance from the multithreaded libraries. the performance of the multithreaded libraries has been improved and is close to the performance of the now-eliminated single-threaded libraries. for those situations when even higher performance is required, there Are several new features. · independent stream locking allows you to lock a stream and then use _ nolock functions that access the stream directly. this allows lock usage to be hoisted outside critical loops. · per-thread locale reduces the cost of locale access for Multithreaded scenarios (see _ configthreadlocale ). · locale-dependent functions (with names ending in _ L) Take the locale as a parameter, Removing substantial cost (for example, printf, _ printf_l, wprintf, _ wprintf_l ). · optimizations for common codepages reduce the cost of your short operations. · defining _ crt_disable_perfcrit_locks forces all I/O operations to assume a single-threaded I/O model and use the _ nolock forms of the functions. this allows highly I/O-based Single-threaded applications to get better performance. · exposure Of the CRT heap handle allows you to enable the windows low fragmentation heap (lfh) for the CRT heap, which can substantially improve performance in highly scaled scenarios. the Runtime Library is the library file required by the program during runtime. Generally, the Runtime Library is provided in the form of LIB or DLL. The C Runtime Library was born in 1970s. At that time, the program world was still very simple. Applications were all single-threaded, and the multi-task or multi-thread mechanism was still a new concept at this time. Therefore, the C Runtime Library in this period is single-threaded. With the development of multi-thread technology in the operating system, the initial C Runtime Library could not meet the needs of the program and encountered a serious problem. The C Runtime library uses multiple global variables (such as errno) and static variables, which may cause conflicts in multi-threaded programs. If both threads set errno at the same time, the result is that the later errno will overwrite the previous one, and the user cannot get the correct error message. Therefore, Visual C ++ provides two versions of the C Runtime Library. One version can be called by a single-threaded application, and the other version can be called by a multi-threaded application. There are two major differences between the multi-thread Runtime Library and the single-thread Runtime Library: (1) global variables similar to errno, each thread sets a separate one. In this way, the correct error information can be obtained from each thread. (2) Data Structures in multi-threaded databases are protected by synchronization mechanisms. This avoids access conflicts. The multi-thread Runtime Library provided by Visual C ++ is divided into static and dynamic link libraries, and each type of Runtime Library can be further divided into debug and release versions, therefore, Visual C ++ provides six runtime libraries. The following table shows the single thread (static link) mllibc library file in the C runtime. libdebug single thread (static link) mldlibcd. libmultithread (static link) mtlibcmt. libdebug multithread (static link) mtdlibcmtd. libmultithread (Dynamic Link) mdmsvert. libdebug multithread (Dynamic Link) mddmsvertd. roles of LIB 2.c runtime libraries C Runtime libraries not only provide us with necessary library function calls (such as memcpy, printf, and malloc, it also provides the most important function to add a startup function for the application. The main function of the C Runtime Library startup function is to initialize the program, assign the initial value to the global variables, and load the user program's entry function. The entry point of the console program that does not use the wide character set is maincrtstartup (void ). Next we will take this function as an example to analyze what kind of Entry Program is added to the Runtime Library for us. This function is defined in crt0.c. The following code has been sorted and simplified by the author: void maincrtstartup (void) {int mainret; _ osver = getversion (); _ winminor = (_ osver> 8) & 0x00ff; _ winmajor = _ osver & 0x00ff; _ winver = (_ winmajor <8) + _ winminor; _ osver = (_ osver> 16) & 0x00ffff; _ ioinit (); _ acmdln = (char *) getcommandlinea (); _ aenvptr = (char *) _ crtgetenvironmentstringsa (); _ setargv (); _ setenvp (); _ cinit (); _ initenv = _ environ; Mai Nret = Main (_ argc, _ argv, _ environ); exit (mainret);} according to the code above, before calling the main or winmain function of the user program, initialization is performed. After Initialization is complete, the main or winmain function we wrote is called. Only in this way can our c-Language Runtime libraries and applications work normally. In addition to crt0.c, the C Runtime Library also contains wcrt0.c, wincrt0.c, and wwincrt0.c files to provide initialization functions. Wcrt0.c is a wide character set version of crt0.c. wincrt0.c contains entry functions of Windows applications, while wwincrt0.c is a wide character set version of wincrt0.c. The source code of the Runtime Library of Visual C ++ is not installed by default. If you want to view its source code, you need to reinstall visual c ++ and select the option to install the source code of the Runtime Library. 3. differences between various C Runtime libraries (1) Single-threaded libraries with static links can only be used for single-threaded applications, the target code of the C Runtime Library is eventually compiled into the binary file of the application. You can use the/ml compilation option to set a single-threaded library that uses static links for Visual C ++. (2) The target code of the static multi-threaded library with static links is finally compiled in the binary file of the application, but it can be used in the multi-threaded program. You can use the/MT compilation option to set a single-threaded library that uses static links for Visual C ++. (3) dynamically linked runtime libraries save all C library functions in a separate Dynamic Linked Library msvcrtxx. dll. msvcrtxx. dll handles multithreading issues. You can use the/MD compilation option to set the Runtime Library that uses dynamic links in Visual C ++. The/MDD,/MLD, or/MTD options use the debug Runtime Library (the runtime function library of the debug version), which corresponds to/MD,/ml, or/MT respectively. The Runtime Library of the debug version contains debugging information and uses some protection mechanisms to help identify errors and enhance the detection of errors. Therefore, it cannot match the release version in terms of running performance. The following shows a console program that does not correctly use the C Runtime Library: # include <stdio. h> # include <afx. h> int main () {cfile file; cstring STR ("I Love You"); try {file. open ("file. dat ", cfile: modewrite | cfile: modecreate);} catch (cfileexception, E) {# ifdef _ debug afxdump <"file cocould not be opened" <e-> m_cause <"\ n"; # endif} end_catch file. write (STR, str. getlength (); file. close ();} The Link error "nafxcwd. lib (thrdco Re. OBJ): Error lnk2001: unresolved external symbol _ endthreadexnafxcwd. lib (thrdcore. OBJ): Error lnk2001: unresolved external symbol implements ininthreadexmain.exe: Fatal error lnk1120: 2 unresolved externalserror executing cl.exe. the cause of the error is that visual C ++ uses a single-threaded static Link Library for the console program by default, while the cfile class in MFC has hidden multiple threads. In Visual C ++ 6.0, choose Project> Settings> C/C ++ menus and options, and modify the compilation options in project options. However, the above program can run in 6.0, and the phenomenon is the same as that in 2003. **************************************** * ****** Literally, the Runtime Library is the library file required for running the program. Generally, the Runtime Library is provided in the form of DLL. The runtime libraries of Delphi and C ++ Builder are. BPL files, which are still DLL files. The Runtime Library generally includes functions frequently used for programming, such as string operations, file operations, and interfaces. The functions supported by different languages are usually different, so the databases used are also completely different. This is why there are VB runtime libraries, C Runtime libraries, and Delphi runtime libraries. Even in C ++, different libraries may be used for different functions. For example, the Runtime library used by VC ++ is completely different from the C ++ builder. If you do not use the Runtime Library, each program will contain a lot of repeated code. Using the Runtime Library can greatly reduce the size of the compiled program. On the other hand, because the Runtime library is used, it is troublesome to include these libraries in the distribution program. If the corresponding running database program cannot be found in the operating system, it cannot be run. To solve this problem, windows always carries the latest Runtime Library of the software it has developed. Versions like Windows 2000 and later include Visual Basic 5.0/6.0 libraries. Internet Explorer always comes with the latest visual c ++ 6.0 library. Windows XP comes with a library of Microsoft. NET 1.0 (for VB. NET and C. Visual c ++, Delphi, and C ++ builder allow users to select whether the compiled program depends on the Runtime Library. However, VB, Foxpro, PowerBuilder, LabWindows/CVI, and Matlab do not allow users to make such choices and must rely on the Runtime Library. Summary after reading so many things above (I guess few people will read so many things with patience, Wahaha), but I still read it completely, the paragraph in the middle is copied and well spoken. Well. One thing is certain, that is, do not use the ml single-threaded version. Moreover, 2005 does not support ml. (Note that Ml is not the abbreviation of make L * ve, Khan !). In addition, ML does not support multithreading. Therefore, if you use ml for compiling and running, there will certainly be many problems, although it does not clearly state what will happen. A problem that has plagued me for a long time has finally been solved. All the problems with changing MLD to MDD are solved, and it is okay to use intel thread checker check. If you encounter the same problem, I hope the above information will be useful to you. If you have any questions, please contact me. If anything is wrong, please criticize and correct it. Well.

 

/MT/MD/ml/MTD/MDD/MLD differences

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.