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)?
In writing Win32 C/C++ code, is there any advantage (e.g. performance?) in using Windows-specific
Share
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.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 thinksmss.exeof Windows is such a process BTW).Having that said, I think that for most applications that doesn’t matter.
UPDATE Since people seem to get so hooked up on the difference of individual functions, in particular
memcpyvs.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 (actuallymemcpyis a good example for that), while others (sensibly) can’t. Something that, I believe, @Merdad hinted in his answer to.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.