I am writing a piece of code that needs to copy values from one char pointer to another. The primary requirements are that the code should work as fast as possible and across as many platforms as possible.
I see that I can do this string copy using either of these two functions:
char * strncpy ( char * destination, const char * source, size_t num );
and
void * memcpy ( void * destination, const void * source, size_t num );
How can I determine what will be best for my requirements?
In general, how can I find out relative speeds of two different functions (across platforms)?
From performance POV,
memcpyis faster, as it doesn’t check the content itself, just copying it.And regarding compatibility – memcpy is part of the C standard.