Run-time link mode

Source: Internet
Author: User

Before introducing the entry function, let's introduce several Run-time libraries (Runtime library) and their corresponding link options:


1.multi-threaded Debug (/MTD) is a debug version of the multithreaded library, statically linked.
2.multi-threaded (/MT)
This is release version of the multithreaded library, statically linked.


3.multi-threaded Debug DLL (/MDD)

This is the debug version of the multithreaded library, dynamically linked.

4.multi-threaded DLL (/MD)

This is release version of the multithreaded library, dynamically linked.


The debug version of the runtime adds code for error checking, such as stack overflow checks, cookie based security checks, and Checkstackvar checks. These additional code can help detect unsafe errors in the encoding. As a result, the debug version is not running at a high rate. The following sections will detail the security Review policy for the debug runtime.

The difference between the static link runtime and the dynamic link runtime is that static links link the entire Run-time code to a module (that is, each module has a run-time code), and dynamic links are used in a shared fashion (that is, each module shares a runtime code). This can lead to different ways of linking, where they have to pay attention to.

1. Adopt/MD option

A. Because the dynamic link is running, the resulting module will be a small size

B. Each module shares a runtime code, then the heap of application and release is very free, a module application heap, b module release heap, so that is available.

2. Adopt/MT option

A. Because it is statically linked, each module will contain a run-time code that naturally increases its volume. However, this can run stably in the absence of a run-time system.

B. Each module contains a run-time code, so you can only release the heap of your application in your own module, otherwise there will be an error.

Note: In the case of multiple modules, you must select the same option and cannot be mixed.


Here is the test scenario:

Add the application heap and release heap code in a DLL, add the same code to the B DLL, and generate them in a different link form (/MD,/MT).

Load the two DLLs in the main program and get their exported functions, respectively.


A DLL code is as follows:

[CPP]  View Plain  copy  // a_dll.cpp :  defines the export function of  DLL  application.   //      #include   "stdafx.h"       char* mallocheap (  int n )    {       if  ( n <= 0  )        {           return  NULL;       }          char*  Pheap = new char ( n );          if  (  pheap )        {            return pheap;       }       else       {           return NULL;    &NBSP;&NBSP;&NBsp; }          return NULL;  }          bool freeheap ( char* pHeap )    {        if  ( pHeap )        {            delete pHeap;           pheap  = NULL;              return TRUE;        }       else        {           return FALSE;        }          return FALSE;  }  

The B DLL code is as follows:

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.