FillChar();
FillMemory();
ZeroMemory();
三者清零其实是一样的。在windows.pas中的定义如下:
procedure FillMemory(Destination: Pointer
Length: DWORD
Fill: Byte);
begin
FillChar(Destination^, Length, Fill);
end;
procedure ZeroMemory(Destination: Pointer
Length: DWORD);
begin
FillChar(Destination^, Length, 0);
end;
而FillChar的实现是这样的(system.pas):
procedure _FillChar;
asm
{ ->EAX Pointer to destination }
{ EDX count }
{ CL value }
PUSH EDI
MOV EDI,EAX { Point EDI to destination }
MOV CH,CL { Fill EAX with value repeated 4 times }
MOV EAX,ECX
SHL EAX,16
MOV AX,CX
MOV ECX,EDX
SAR ECX,2
JS @@exit
REP STOSD { Fill count DIV 4 dwords }
MOV ECX,EDX
AND ECX,3
REP STOSB { Fill count MOD 4 bytes }
@@exit:
POP EDI
end;
-------------------------------------------------------------
所以我觉得FillChar并不只是对字符能清零,它以字节为单位,对某一段内存清零。
卷哥说得对,在汇编中还是用到了循环。