Memset Definition and use

后端 未结 6 688
失恋的感觉
失恋的感觉 2020-12-12 16:24

What\'s the usefulness of the function memset()?.

Definition: Sets the first num bytes of the block of memory pointed by

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 17:09

    memset() is a very fast version of a relatively simple operation:

    void* memset(void* b, int c, size_t len) {
        char* p = (char*)b;
        for (size_t i = 0; i != len; ++i) {
            p[i] = c;
        }
        return b;
    }
    

    That is, memset(b, c, l) set the l bytes starting at address b to the value c. It just does it much faster than in the above implementation.

提交回复
热议问题