A
Alessio Sangalli
Hi, I am building up a buffer in memory to be sent over the network as a
data structure.
In the following example, I will omit all the hton* calls for simplicity.
Imagine I have a char buffer[16] and I have to fill it up with a number
of small, 16bit values.
What I did is to define a macro:
#define CPY16(d,s) *(uint16_t*)&d=s
and then use it as follows:
uint16_t a=0xfaaf;
uint16_t b=0xc33c;
CPY16(buffer[12], a);
CPY16(buffer[2], b);
I did this because profiling revealed that the version above is almost
10 times faster than memcpy().
Where's the catch? Am I implementation/compiler/architecture dependent?
bye, thank you
Alessio
data structure.
In the following example, I will omit all the hton* calls for simplicity.
Imagine I have a char buffer[16] and I have to fill it up with a number
of small, 16bit values.
What I did is to define a macro:
#define CPY16(d,s) *(uint16_t*)&d=s
and then use it as follows:
uint16_t a=0xfaaf;
uint16_t b=0xc33c;
CPY16(buffer[12], a);
CPY16(buffer[2], b);
I did this because profiling revealed that the version above is almost
10 times faster than memcpy().
Where's the catch? Am I implementation/compiler/architecture dependent?
bye, thank you
Alessio