Why is msvcrt (very very) slow?

最后都变了- 提交于 2019-12-08 04:41:17

问题


I'm specifically asking about the old msvcrt.dll. Hasn't Microsoft updated that library in newer versions of windows? or is that exactly the same library that one can find in Windows 98 distros?

I tested msvcrt against Cygwin with a test program that calls malloc a lot of times by a singly linked list blocking queue with mutexes and semaphores. By ifdefs, the program can be compiled to use Posix functions or else use Windows API calls. When compiled by MinGW with WinAPI calls the only dependency it has is kernel32.dll, ntdll.dll, and msvcrt.dll, while when compiled by Cygwin with Posix functions, the program will depend on cygwin1.dll.

I at first simply assumed that the Cygwin version will run slower because of the extra emulation layer for Posix functions; it has to translate them to WinAPI calls. But it appears that it runs 4 times faster in my machine than the MinGW compiled native binary.

The documentation of Cygwin states that it uses a different libc called newlib, and certainly the Cygwin-compiled binary does not appear to depend on msvcrt. So is this making the huge speed difference?

I have also experienced before, that when a C program calls millions of mallocs, one that depends on msvcrt.dll will run many times slower than any others depending on newer msvcrXX.dll. They even ran slower than the same program running under a virtual machine linux.

What's wrong with msvcrt.dll? Should I avoid it whenever possible?

来源:https://stackoverflow.com/questions/29954038/why-is-msvcrt-very-very-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!