zoukankan      html  css  js  c++  java
  • 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.

     

     

     


  • 相关阅读:
    基础MYSQl技巧集锦
    C MySQL float类型数据 用 printf()打印
    1Tomcat+Axis+Eclipse实例讲解 2自己做的一个可以用的webservice,只是开始 (WebService好文)
    信号量 进程 (m个生产者,n个消费者,容量为r的缓冲区)
    信号量和同步互斥
    C语言 wait()信号量部分 signal()信号量部分代码
    Tomcat+Axis+Eclipse实例讲解
    MySQL 集合 补集
    SELECT DocID, SUM(a.Score + B.Score) AS TOTAL Itemset_ONE a LEFT Join Itemset_Two b ON a.DocID=b.DocID 太慢
    Yii AR Model 查询
  • 原文地址:https://www.cnblogs.com/shangdawei/p/3051674.html
Copyright © 2011-2022 走看看