ZeroMemory

この関数は参照によって渡された変数をリセットします。

void  ZeroMemory(
  void & variable      // 変数をリセットする
  );

パラメータ

variable

[in] [out]  リセットされる、参照によって渡された変数(ゼロに初期化する)

戻り値

なし

注意事項

この関数の呼び出しは、引数が文字列である場合、その値として NULL を示すのと同じです。
基本データ型とその配列、また基本データ型の構造体とクラスにとっては、これはただのリセットと同じです。
文字列と動的配列を含むオブジェクトの場合、ZeroMemory() が各要素に対して呼び出されます。
const 修飾子によって保護されていない任意の配列の場合、すべての要素がゼロで初期化されます。
複合オブジェクトの配列の場合、ZeroMemory() が各要素に対して呼び出されます。

ZeroMemory() は protected メンバ継承クラスを持つクラスでは使用できません。

Example:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
 {
//--- declare and initialize the string
  string str="Test ZeroMemory func";
//--- send the line to the log before applying ZeroMemory() to it
  PrintFormat("The line before applying ZeroMemory() to it: '%s'",str);
//--- reset the string and send the result to the log
  ZeroMemory(str);
  Print("The same line after applying ZeroMemory() to it: '",str,"'");
 /*
  Result:
  The line before applying ZeroMemory() to it: 'Test ZeroMemory func'
  The same line after applying ZeroMemory() to it: ''
 */
 
//--- declare and initialize the variable of int type
  int var=123;
//--- send the line to the log before applying ZeroMemory() to it
  PrintFormat("\nThe integer variable before applying ZeroMemory() to it: %d",var);
//--- reset the variable and send the result to the log
  ZeroMemory(var);
  PrintFormat("The same variable after applying ZeroMemory() to it: %d",var);
 /*
  Result:
  The integer variable before applying ZeroMemory() to it: 123
  The same variable after applying ZeroMemory() to it: 0
 */
 
//--- declare and initialize the array of int type
  int arr[]={0,1,2,3,4,5,6,7,8,9};
//--- send the array to the log before applying ZeroMemory() to it
  Print("\nThe integer array before applying ZeroMemory() to it:");
  ArrayPrint(arr);
//--- reset the array and send the result to the log
  ZeroMemory(arr);
  Print("The same array after applying ZeroMemory() to it:");
  ArrayPrint(arr);
 /*
  Result:
  The integer array before applying ZeroMemory() to it:
  0 1 2 3 4 5 6 7 8 9
  The same array after applying ZeroMemory() to it:
  0 0 0 0 0 0 0 0 0 0
 */
 
//--- declare a structure of two fields - string and integer ones
  struct STest
    {
    string   var_string;
    long     var_long;
    };
//--- declare and initialize the array of STest structure type
  STest arr_struct[]={ {"0",0}, {"1",1}, {"2",2}, {"3",3} };
//--- send the array to the log before applying ZeroMemory() to it
  Print("\nThe array struct before applying ZeroMemory() to it:");
  ArrayPrint(arr_struct);
//--- reset the structure array and send the result to the log
  ZeroMemory(arr_struct);
  Print("The same array struct after applying ZeroMemory() to it:");
  ArrayPrint(arr_struct);
 /*
  Result:
  The array struct before applying ZeroMemory() to it:
      [var_string] [var_long]
  [0] "0"                   0
  [1] "1"                   1
  [2] "2"                   2
  [3] "3"                   3
  The same array struct after applying ZeroMemory() to it:
      [var_string] [var_long]
  [0] null                 0
  [1] null                 0
  [2] null                 0
  [3] null                 0
 */
 }