ZeroMemory和memset的区别:
1、ZeroMemory是
微软的SDK提供的,memset是属于C Run-time Library提供的。因此ZeroMemory只能用于Windows系统,而memset还可用于其他系统。
2、ZeroMemory是一个宏,只是用于把一段
内存的内容置零,内部其实是用 memset实现的,而memset除了对内存进行清零操作,还可以将内存置成别的字符。
3、如果程序是Win32程序而且不想连接c
运行时库,就用ZeroMemory;如果需要跨平台,就用memset。
所以,如果ZeroMemory和memset用于清零操作,其本质是一样的。
ZeroMemory和 “={0}”的区别:
1、ZeroMemory会将结构中所有
字节置0,而“={0}”只会将成员置0,其中填充字节不变。
2、一个struct有
构造函数或
虚函数时,ZeroMemory可以编译通过,而“={0}”会产生编译错误。其中,“={0}”的编译错误起到了一定的保护作用,因为对一个有
虚函数的对象使用ZeroMemory时,会将其虚函数的指针置0,这是非常危险的(调用虚函数时,空指针很可能引起程序崩溃)。
ZeroMemory function
声明
void ZeroMemory( PVOID Destination,SIZE_T Length );
参数
Destination :指向一块准备用0来填充的
内存区域的开始地址。
返回值
无
SecureZeroMemory function
Fills a block of memory with zeros. It is designed to be a more secure version of ZeroMemory.
Syntax
PVOID SecureZeroMemory(
_In_ PVOID ptr,
_In_ SIZE_T cnt
);
_In_ PVOID ptr,
_In_ SIZE_T cnt
);
Parameters
-
ptr [in]
-
A pointer to the starting address of the block of memory to fill with zeros.
cnt [in]
-
The size of the block of memory to fill with zeros, in bytes.
Return value
This function returns a pointer to the block of memory.