Hi,
For copying data from a buffer to a struct, it faster to do a memcpy() or copy things manually. For example:
I think doing it manually would be faster, but I'm not sure. Moreover, when loading a 32 bit word, does the CPU do four fetches, or are the four bytes all sent in one shot?Code:char buf[12]; typedef struct A { int a; int b; int c; } A; A a; memcpy(&a, buf, sizeof(A)); // or a.a = *(int *) buf; a.b = *(int *) (buf + 4); a.c = *(int *) (buf + 8);
Thanks.