Win32 API functions vs. their CRT counterparts (e.g. CopyMemory vs. memcpy)

后端 未结 2 757
走了就别回头了
走了就别回头了 2021-01-05 00:46

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 01:24

    It depends on the function and your requirements.

    For things like memcpy, there isn't any point whatsoever to choosing the Windows-specific versions. Stick with standard C to keep it simple and portable.

    For other things like mbstowcs, you might need to use things like MultiByteToWideChar instead -- depending on what functionality you need.

    Personally I go for the C versions if possible, and only go for Win32 versions afterwards -- because there's really no reason to write Windows-specific code when it could be written portably.

提交回复
热议问题