您的位置:首页 > 其它

操作内存的一些函数

2010-03-17 13:35 453 查看

1.CopyMemory

CopyMemory()
函数功能描述:将一块内存的数据从一个位置复制到另一个位置
Delphi 函数原型 procedure CopyMemory(Destination: Pointer; Source: Pointer; Length: DWORD);
C++ 函数原型
VOID CopyMemory(
PVOID Destination,
CONST VOID *Source,
DWORD Length
);
参数
Destination
要复制内存块的目的地址。
Source
要复制内存块的源地址。
Length
指定要复制内存块的大小,单位为字节
返回值
该函数为VOID型,没有返回值。
备注
如果目的块与源块有交叠,结果是不可预料的,使用MoveMemory可以解决这个问题。
2.MoveMemory
使用MoveMemory复制数据
procedure MoveMemory(Destination: Pointer; Source: Pointer; Length: DWORD);
MoveMemory参数意义:(1)Destination:目的数据的地址;(2)Source:来源数据的
地址;(3)Length:数据的字节数
var Rect1,Rect2:TRect;
begin
  Rect1.Left:=10;
  Rect1.Top:=10;
  Rect1.Bottom:=200;
  Rect1.Right:=200;
  Rect2.Left:=50;
  Rect2.top:=100;
  Rect2.Bottom:=400;
  Rect2.Right:=390;
  form1.Canvas.FillRect(Rect1);
  showmessage('movemory!');
  form1.Refresh;
  windows.MoveMemory(@rect1,@rect2,sizeof(TRect));
  form1.Canvas.FillRect(rect1);
end;
结果把rect2的值赋到rect1中
移动数组的值
一般的办法:
var s1,s2:array[0..4] of integer;
    i:integer;
begin
  s1[0]:=1;
  s1[1]:=2;
  s1[2]:=3;
  s1[3]:=4;
  s1[4]:=5;
  s2[0]:=6;
  s2[1]:=7;
  s2[2]:=8;
  s2[3]:=9;
  s2[4]:=0;
  for a:=0 to 4 do s1[a]:=s2[a];
end;
用movemeory的办法:
var s1,s2:array[0..4] of integer;
    i:integer;
begin
  s1[0]:=1;
  s1[1]:=2;
  s1[2]:=3;
  s1[3]:=4;
  s1[4]:=5;
  s2[0]:=6;
  s2[1]:=7;
  s2[2]:=8;
  s2[3]:=9;
  s2[4]:=0;
  for i:=0 to 4 do showmessage('s1的'+inttostr(i)+':'+inttostr(s1[i]));
  showmessage('movemeory1!');
  windows.MoveMemory(@s1,@s2,sizeof(s1));
  for i:=0 to 4 do showmessage('s1的'+inttostr(i)+':'+inttostr(s1[i]));
end;
 
procedure FillMemory(Destination: Pointer; Length: DWORD; Fill: Byte);
{$EXTERNALSYM FillMemory}
procedure ZeroMemory(Destination: Pointer; Length: DWORD);
{$EXTERNALSYM ZeroMemory}
procedure       Move( const Source; var Dest; count : Integer );
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: