I have a block of memory with elements of fixed size, say 100 bytes, put into it one after another, all with the same fixed length, so memory looks like this
&l
The obvious portable, high efficiency method is:
char testblock [fixedElementSize];
memset (testblock, 0, sizeof testblock);
if (!memcmp (testblock, memoryBlock + elementNr*fixedElementSize, fixedElementSize)
// block is all zero
else // a byte is non-zero
The library function memcmp()
in most implementations will use the largest, most efficient unit size it can for the majority of comparisons.
For more efficiency, don't set testblock
at runtime:
static const char testblock [100];
By definition, static variables are automatically initialized to zero unless there is an initializer.