TripleS TripleS - 1 year ago 68
C++ Question

Is it possible to store 8 bytes in single command

I'm writing a real time code, so time is matter

I'm using C++ Intel instincts

I wonder whether is it possible to store 8 unsigned char (8 bytes) in single command instead of using a loop ?

char* buff = foo();
for (auto i = 0; i < 8; i++)
buff[i] = 0x00;

Looking for something similar to


I thought of doing this, but this doesn't work (I don't know why)

_int64* buff = foo();
*buff = 0x00000000;

Any suggestions for faster code ?

Answer Source
char* buff = foo();
*((uint64_t*)buff) = 0;

Or am I missing something?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download