Delphi Memory 函数
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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本