[Info] MD vs MT && Unicode vs ANSI

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
kyuuuri
Posts: 336
Joined: 09 Jan 2016, 19:20

[Info] MD vs MT && Unicode vs ANSI

Post by kyuuuri » 03 Mar 2020, 01:54

/MD (Multi-threaded DLL) versions

When compiling with /MD the dlls are not included with the .exe, that's why you have to distribute vcruntime140.dll with the exe (unless the user has Visual C++ Redistributable for Visual Studio 2015 installed)

Pros:
  • The executable will be smaller. (only 1-2 MB)
  • The code segment of a DLL is shared amongst all processes that are actively using it (reducing the total amount of RAM consumed). (Only a few MB, needs to be measured)
  • Will allow to modify/delete/create memory from dll in exe, exe in dll and dll in dll.
Cons:
  • You need to distribute the dll with the exe or tell the user to install vcredist2015.
Mixed (depends on the situation):
  • If you make users install vcredist2015 then the dll will be exposed to system updates. This sounds great but at the same time it can break your software. Depending on the complexity of your software and the chances of a breaking update on the .dll you are better off distributing the .dll yourself. When a new dll version is released then you can update your software accordingly and distribute it alongside the new version of the dll. Is up to you to decide if not being exposed to updates is good or bad.
/MT (Multi-threaded) versions

When compiling with /MT it means that the dlls are included with the .exe.

Pros:
  • You don't need to distribute the dll with the exe.
Cons:
  • The executable is bigger. (Only 1-2MB)
  • It will use more RAM. (Only a few more MB, needs to be measured)
  • It is very likely to cause memory leaks and crash your exe. (CriticalObject, VirtualAlloc, HeapAlloc, etc.)
Mixed (depends on the situation)
  • The dll is not exposed to system updates: some might prefer to use the latest version but this is not always the best idea on software development. When the software is small it's easy to adapt if a new dll version requires it but when you have a software with 20-30k lines of code it becomes extremely hard to maintain.
    Sometimes the update is not worth it, sometimes it is. These updates can vary from something simple like a typo fix to something important like a security patch or a change on a function's parameters. Is up to you to decide if not being exposed to updates is good or bad.

ANSI vs Unicode
  1. Both are character encodings (actually Unicode refers to the character set), ANSI is very old while Unicode is the current standard we use today.
  2. ANSI programs are slower than Unicode.
  3. Unicode programs won't work on old computers.
  4. With your ANSI exe you won't be able to use characters like "Ç" or "Ñ"
Last edited by kyuuuri on 08 Jan 2021, 03:55, edited 3 times in total.
SOTE
Posts: 1211
Joined: 15 Jun 2015, 06:21

Re: [Info] MD vs MT && Unicode vs ANSI

Post by SOTE » 10 Mar 2020, 10:44

In regards to MD vs MT, what you are saying are cons, may not be viewed as such by everyone.

1. In the year 2020, with people having terabyte sized drives, a difference of 1MB or less is often inconsequential.

2. That a program uses slightly more memory, in say a 8GB to 16GB RAM having desktop computer, is also arguably inconsequential.

3. Many people don't want the application they send out to others to be exposed to updates, as they aren't actively supporting it. Even if they are, they can recompile a new version that will upgrade the old version of the app.

4. Memory leaks would be the best argument, but this would also be relative to the skill of the programmer and depend on the type of the application. The type of application created may not have memory issues or the code in it is constructed so that the total amount of RAM used is monitored and limited.

I'm not saying that MD or MT is superior to the other, rather it's much more about the preference of the author creating the application.
User avatar
Tomer
Posts: 336
Joined: 21 Aug 2016, 05:11

Re: [Info] MD vs MT && Unicode vs ANSI

Post by Tomer » 24 Mar 2020, 07:25

Thanks for the info!
kyuuuri
Posts: 336
Joined: 09 Jan 2016, 19:20

Re: [Info] MD vs MT && Unicode vs ANSI

Post by kyuuuri » 08 Jan 2021, 04:03

SOTE wrote:
10 Mar 2020, 10:44
In regards to MD vs MT, what you are saying are cons, may not be viewed as such by everyone.

1. In the year 2020, with people having terabyte sized drives, a difference of 1MB or less is often inconsequential.

2. That a program uses slightly more memory, in say a 8GB to 16GB RAM having desktop computer, is also arguably inconsequential.

3. Many people don't want the application they send out to others to be exposed to updates, as they aren't actively supporting it. Even if they are, they can recompile a new version that will upgrade the old version of the app.

4. Memory leaks would be the best argument, but this would also be relative to the skill of the programmer and depend on the type of the application. The type of application created may not have memory issues or the code in it is constructed so that the total amount of RAM used is monitored and limited.

I'm not saying that MD or MT is superior to the other, rather it's much more about the preference of the author creating the application.
Hello, sorry for taking so long to answer I had a rough year. I updated the post to reflect that:
  • While it is true that less ram usage is better, a few MB (on modern computers) won't make a difference. That's why it's still a pro but an explanation is given to show how impactful this is
  • While it is true that reducing the size of a program is better, a few MB shouldn't make a difference. It matters a lot when dealing with slow internet or very limited data usage. That's why it's still a pro but an explanation is given to show how impactful this is.
  • Moved the "exposed to system updates" to a category called "Mixed" because it depends on the situation.
  • I didn't experience any memory leak myself (when programming on AhK) but I always used /MD, that's why I leave that con exactly as explained by HotKeyIt
I hope this makes the post be seen more about the differences between those 2 and not a direct comparison with a conclusion on which one is better.
guest3456
Posts: 3163
Joined: 09 Oct 2013, 10:31

Re: [Info] MD vs MT && Unicode vs ANSI

Post by guest3456 » 09 Jan 2021, 21:55

kyuuuri wrote:
03 Mar 2020, 01:54
When compiling with /MD the dlls are not included with the .exe, that's why you have to distribute vcruntime140.dll with the exe
do we just have to distribute it in the same root directory as the exe would be launched from?

guest3456
Posts: 3163
Joined: 09 Oct 2013, 10:31

Re: [Info] MD vs MT && Unicode vs ANSI

Post by guest3456 » 13 Feb 2021, 14:32

where do i find this vcruntime140.dll to distribute with my app?

when i compile with vs2017 there is no .dll file inside the /win32w/bin/ output folders

also, if the user has both vcredist2015 and the vcruntime dll in the app folder, which takes precedence?

kyuuuri
Posts: 336
Joined: 09 Jan 2016, 19:20

Re: [Info] MD vs MT && Unicode vs ANSI

Post by kyuuuri » 14 Feb 2021, 17:09

guest3456 wrote:
13 Feb 2021, 14:32
where do i find this vcruntime140.dll to distribute with my app?

when i compile with vs2017 there is no .dll file inside the /win32w/bin/ output folders

also, if the user has both vcredist2015 and the vcruntime dll in the app folder, which takes precedence?
You can find vcruntime140.dll in Visual Studio's folder, I don't remember the exact folder. I believe you can find it on Windows' folder as well but I'm not sure.

The file on the folder always takes precedence.
SOTE
Posts: 1211
Joined: 15 Jun 2015, 06:21

Re: [Info] MD vs MT && Unicode vs ANSI

Post by SOTE » 14 Feb 2021, 23:52

You can download the Microsoft Visual C++ Redistributable 2015, 2017 and 2019 (make sure to only download from Microsoft to avoid fakes and malware).
https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0

When you install it, where the dll will be put is a bit tricky, depending on if you have Visual Studio installed and what version. If you are recompiling, you should have Visual Studio, so the search will be narrower for the vcruntime140.dll. Usually you would search under C:\Program Files (x86)\Microsoft Visual Studio\.

If going the /MD route, you would usually put the vcruntime140.dll with the AHK_H executable in the same folder. However, I think you can also have users download the Visual C++ Redistributable or your program install it, and the /MD AHK_H executable would still work. vcruntime140.dll wouldn't be in the same folder as your AHK_H program, but the Windows OS would be able to find it.
Post Reply

Return to “AutoHotkey_H”