Win32 API函数与他们同行的CRT(例如CopyMemory的主场迎战的memcpy) [英] Win32 API functions vs. their CRT counterparts (e.g. CopyMemory vs. memcpy)

查看:321
本文介绍了Win32 API函数与他们同行的CRT(例如CopyMemory的主场迎战的memcpy)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在写的Win32 C / C ++ code,它有什么优势在使用类似 lstrcpyn Windows的特定功能(如性能?)或 CopyMemory的,而不是对应CRT功能(除了的CRT函数的可移植性)?

In writing Win32 C/C++ code, is there any advantage (e.g. performance?) in using Windows-specific functions like lstrcpyn or CopyMemory instead of the corresponding CRT functions (aside from portability of CRT functions)?

推荐答案

目前至少有一些CRT函数使用Win32函数内部。另外,CRT需要额外的初始化(例如线程功能的具体数据,如 strtok的)和清理,你可能不希望有发生。

At least some CRT functions use the Win32 functions internally. Also the CRT requires additional initialization (e.g. thread specific data for functions like strtok) and cleanup, that you might not want to have to happen.

您可以创建一个简单的Win32应用程序,而不会对任何其他包括CRT(就像你的任何依赖性可能的使用创建一个纯NT应用程序 NTDLL.DLL - 我认为 SMSS.EXE 是BTW这样一个过程)

You could create a plain Win32 application, without any dependency on anything else including the CRT (much like you could create a plain NT application using NTDLL.DLL - I think smss.exe of Windows is such a process BTW).

有了这样说,我认为,对于大多数应用程序,这并不重要。

Having that said, I think that for most applications that doesn't matter.

更新由于人们似乎变得这么勾搭上的各个功能的差异,特别是的memcpy CopyMemory的,我想补充一点的不可以在CRT的所有功能都是围绕那些在Win32中包装。当然,有些可以没有任何帮助从Win32的(实际上是的memcpy 是一个很好的例子),而其他(理智)不能。东西,我相信,@Merdad暗示在他的回答。

UPDATE Since people seem to get so hooked up on the difference of individual functions, in particular memcpy vs. CopyMemory, I would like to add that not all functions in CRT are wrappers around those in Win32. Naturally, some can be implemented without any help from Win32 (actually memcpy is a good example for that), while others (sensibly) can't. Something that, I believe, @Merdad hinted in his answer to.

所以,抛开便携性,我不认为性能是反对使用CRT进行的的下一个最好的论据。
你应该选择最适合自己的最好,通常是CRT。并没有什么讲话反对使用单独的Win32函数(CRT与当量),在这里你似乎契合。

So, portability aside, I don't think performance is the next best argument for or against using the CRT. You should choose what fits best and that typically will be the CRT. And there is nothing speaking against using individual Win32 functions (with CRT equivalents), where you seem fit.

这篇关于Win32 API函数与他们同行的CRT(例如CopyMemory的主场迎战的memcpy)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆