------- Additional Comments From jblomqvi at cc dot hut dot fi 2005-09-08 21:25 ------- Huh, I don't see how this relates to PR 23356. Surely you wrote the wrong number?
Anyway, I don't think memcpy is that bad. Consider the following program: #include <stdio.h> #include <time.h> #include <string.h> #define LEN 100000000 char foo[LEN], bar[LEN]; int main (void) { int i; clock_t beg, as, mc, mc2; beg = clock (); for (i = 0; i < LEN; i++) { foo[i] = bar[i]; } as = clock () - beg; beg = clock (); memcpy (&foo, &bar, LEN); mc = clock () - beg; beg = clock (); for (i = 0; i < LEN/4; i++) { memcpy (&foo[i], &bar[i], 4); } mc2 = clock () - beg; printf ("Copying char arrays with assignment took %d cycles.\n", as); printf ("Using memcpy () it took %d cycles.\n", mc); printf ("Copying 4 byte blocks (real, int) with memcpy () took %d cycles.\n", mc2); } On my computer, compiled without optimization I get: Copying char arrays with assignment took 790000 cycles. Using memcpy () it took 90000 cycles. Copying 4 byte blocks (real, int) with memcpy () took 500000 cycles. And with -O2 I get Copying char arrays with assignment took 290000 cycles. Using memcpy () it took 90000 cycles. Copying 4 byte blocks (real, int) with memcpy () took 60000 cycles. So, memcpy is very fast. Of course, alignment always helps, and that is perhaps an orthogonal issue wrt memcpy vs. looping. But I'm not sure which variables you want to be better aligned. The buffers in struct unix_stream, or? Anyway, gcc has __attribute__ ((aligned (num_bytes))) which I think could be used. See http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/Variable-Attributes.html -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23770