• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

DelphiMemory函数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
procedure MoveMemory(Destination: Pointer; Source: Pointer; Length: NativeUInt);
begin
  Move(Source^, Destination^, Length);
end;

procedure CopyMemory(Destination: Pointer; Source: Pointer; Length: NativeUInt);
begin
  Move(Source^, Destination^, Length);
end;

procedure FillMemory(Destination: Pointer; Length: NativeUInt; Fill: Byte);
begin
  FillChar(Destination^, Length, Fill);
end;

procedure ZeroMemory(Destination: Pointer; Length: NativeUInt);
begin
  FillChar(Destination^, Length, 0);
end;


procedure FillChar(var X; Count: Integer; Value: Ordinal);
 

Fills contiguous bytes with a specified value.
In Delphi, FillChar fills Count contiguous bytes (referenced by X) with the value specified by Value (Value can be of type Byte or AnsiChar) 

Note
that if X is a UnicodeString, this may not work as expected, because FillChar expects a byte count, which is not the same as the character count.

In addition, the filling character is a single-byte character. 
Therefore, when Buf is a UnicodeString, the code FillChar(Buf, Length(Buf), #9); 
fills Buf with the code point $0909, not $09. In such cases, 

you should use the StringOfChar routine. 

Warning: This function does not perform any range checking.
Warning: This method has an untyped parameter, which can lead to memory corruption.
To avoid this problem, use SizeOf to find the number of bytes appropriate to fill for the data type of the X parameter.

function SizeOf(var X): Integer;

Returns the number of bytes occupied by a variable or type.
Pass a Delphi variable reference to SizeOf to determine the number of bytes used to represent the variable.
Pass a type identifier to SizeOf to determine the number of bytes used to represent instances of that type.
SizeOf is useful for determining the amount of memory to specify for the FillChar, Move, or GetMem procedures.
SizeOf returns 0 when the argument is an untyped variable.

procedure Move(const Source; var Dest; Count: NativeInt);

Copies bytes from a source to a destination.
Move copies Count bytes from Source to Dest.
No range checking is performed. Move compensates for overlaps between the source and destination blocks.
Whenever possible, use the global SizeOf function (Delphi) to determine the count.
Note:
This method has an untyped parameter (Dest), which can lead to memory corruption.
To avoid this problem, use SizeOf to determine the number of bytes appropriate
to "move" for the data type being used in Count parameter.

 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Matlab批量修改文件夹名字发布时间:2022-07-18
下一篇:
matlab中randn(‘state’)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap