操作内存的一些函数
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 );
相关文章推荐
- 一些字符串及内存操作函数的实现
- 一些字符串及内存操作的函数
- 实现的一些内存辅助操作函数
- 一些字符串及内存操作的函数的实现
- C/C++ 内存操作函数集合(Buffer Manipulation)
- 共享内存和操作共享内存几个函数的用法
- linux 文件操作函数 通过例子来解释 父子间文件描述符共享 内存映像图
- Delphi 的内存操作函数(1): 给字符指针分配内存
- C语言中内存操作函数 - malloc/calloc ,free
- C语言一些常用的“位”操作函数
- Libevent源码分析-----与event相关的一些函数和操作
- 对32位的无符号int的位进行操作的一些相关函数
- C++友元friend --c++利用friend修饰符,可以让一些你设定的函数能够对这些保护数据进行操作
- Delphi 的内存操作函数(3): 给结构体指针分配内存
- C内存操作函数memmove()与memset()区别
- OPEN函数需要做的一些操作
- C——常用字符串函数、内存操作函数总结
- 文件操作的一些函数
- 内存操作函数
- 关于函数中内存操作