c++里面有没有以下相类似的移动内存数据的函数?3Q
====================================================================================
Delphi System单元 - Move - 移动内存数据,不分类型 untyped
单元:System
Move 原型:
procedure Move( const Source; var Dest; count : Integer );
var
S, D: PChar;
I: Integer;
begin
S := PChar(@Source); //指针地址
D := PChar(@Dest); //
if S = D then Exit;
if Cardinal(D) > Cardinal(S) then
for I := count-1 downto 0 do
D[I] := S[I]
else
for I := 0 to count-1 do
D[I] := S[I];
end
还有一段汇编的原型:
登录后复制
procedure Move( const Source; var Dest; count : Integer );
asm
{ ->EAX Pointer to source }
{ EDX Pointer to destination }
{ ECX Count }
PUSH ESI
PUSH EDI
MOV ESI,EAX
MOV EDI,EDX
MOV EAX,ECX
CMP EDI,ESI
JA @@down
JE @@exit
SAR ECX,2 { copy count DIV 4 dwords }
JS @@exit
REP MOVSD
MOV ECX,EAX
AND ECX,03H
REP MOVSB { copy count MOD 4 bytes }
JMP @@exit
@@down:
LEA ESI,[ESI+ECX-4] { point ESI to last dword of source }
LEA EDI,[EDI+ECX-4] { point EDI to last dword of dest }
SAR ECX,2 { copy count DIV 4 dwords }
JS @@exit
STD
REP MOVSD
MOV ECX,EAX
AND ECX,03H { copy count MOD 4 bytes }
ADD ESI,4-1 { point to last byte of rest }
ADD EDI,4-1
REP MOVSB
CLD
@@exit:
POP EDI
POP ESI
end;
以上可以看出Move 的功能是很强大的,也可以直接用汇编来编译, 简单的可以理解为:Move 移动内存数据,不分类型 {解释权归本博客,如有错,请指出,谢谢}
※ 修改:·mazheng75 于 Nov 12 06:00:20 2022 修改本文·[FROM: 123.113.225.*]
※ 来源:·水木社区
http://www.mysmth.net·[FROM: 123.113.225.*]
修改:mazheng75 FROM 123.113.225.*
FROM 123.113.225.*