Delphi Memory 함수
2993 단어 Delphi
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)
Notethat 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 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[Delphi] TStringBuilder그리고 꼭 사용해야만 할까? 그림처럼 Heap 영역에 "Hello" 공간을 생성하고 포인팅을 한다. "Hello World" 공간을 새로 생성한 후 포인팅을 하게 된다. 결국 "Hello" 라는 String 객체가 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.