char buffer[424242] = {0};
Is buffer[index] as fast as *buffer?
for (int i = 0; i < SIZE; ++i) {
buffer[i] = 42;
}
char* end = buffer + SIZE;
for (char* pos = buffer; pos != end; ++pos) {
*pos = 42;
}
I guess my question is, is there any assembly instruction that can set a position in memory plus and offset to a given value in a single cycle?
LEA seems to load the address plus multiply it in this way.
*bufferis at least as fast asbuffer[index]. Depends onindex. Ifindex == 0, they’ll be equally fast.As per your edit:
invokes undefined behavior because you don’t initialize
pos.As per your second edit:
Write your code for readability first, profile & possibly change only after you have some concrete results.
is way more readable, stick to it.