问题描述
我有点明白什么 memset的定义()
是。不过,我不明白它的点是。
I understand slightly what the definition of memset()
is. However, I don't understand what the point of it is for.
定义:设置内存ptr指向指定值块的第一NUM个字节(除preTED为unsigned char)
Definition: Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).
那么,这很难code值在内存地址?
So does this hard code a value in a memory address?
memset的(安培; serv_addr,0,sizeof的(serv_addr)
是我想了解的例子
有人可以在一个非常简单的方式解释一下吗?
Can someone please explain in a VERY simplified way?
推荐答案
memset的()
是一个相对简单的操作非常快的版本:
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;
}
这就是 memset的(B,C,L)
设置→起始地址
字节 b
的值 C
。它只是它比上面的实现快得多。
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.
这篇关于MEMSET定义和使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!