Is there memset() that accepts integers larger than char?

前端 未结 8 602
时光说笑
时光说笑 2020-12-05 00:25

Is there a version of memset() which sets a value that is larger than 1 byte (char)? For example, let\'s say we have a memset32() function, so using it we can do the followi

8条回答
  •  温柔的废话
    2020-12-05 00:56

    You should really let the compiler optimize this for you as someone else suggested. In most cases that loop will be negligible.

    But if this some special situation and you don't mind being platform specific, and really need to get rid of the loop, you can do this in an assembly block.

    //pseudo code
    asm
    {
        rep stosq ...
    }
    

    You can probably google stosq assembly command for the specifics. It shouldn't be more than a few lines of code.

提交回复
热议问题