c - Fastest way to copy an array - Does it have something questionable? -


when working arrays of same length, consider creating structure contains array easier copy array copying structure one.

the definition , declaration of structure this:

typedef struct {     char array[x]; /* x arbitrary constant */ } array;  array array1; 

then, perform copy doing:

array array2; array2 = array1; 

i have found fastest way of copying array. have disadvantage?

edit: x arbitrary constant, let's 10. array not variable length array.

this works fine, since x must defined @ compile-time rather inflexible. can same performance on array of length using memcpy instead. in fact, compilers translate array2 = array1 call memcpy.


as mentioned in comments, whether direct assignment gets translated memcpy call depends on size of array amongst other compiler heuristics.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -