How to check whether all bytes in a memory block are zero

后端 未结 10 882
渐次进展
渐次进展 2021-02-03 21:05

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         


        
10条回答
  •  感动是毒
    2021-02-03 21:52

    AFAIK there is no automatically function to check memory.

    You could use | to speed up the for-loop, no need for "=="

    char *elementStart = memoryBlock + elementNr*fixedElementSize;
    char special = 0;
    for ( size_t curByteNr=0; curByteNr

    and also can you use long for even more speed

    char *elementStart = memoryBlock + elementNr*fixedElementSize;
    long special = 0;
    for ( size_t curByteNr=0; curByteNr

    WARNING: the above code is not tested. Please test it first so that the sizeof and casting operator works

提交回复
热议问题