ArrayIsDynamic

判断动态数组的函数。

bool  ArrayIsDynamic(

   const void&  array[]    // 已检测的数组

   );

参量

array[]

[in]  检测数组.

返回值

数组是动态,返回 true,否则返回 false。

示例:

#property description "This indicator does not calculate values. It makes a single attempt to"

#property description "apply the call of ArrayFree() function to three arrays: dynamic one, static one and"

#property description "an indicator buffer. Results are shown in Experts journal."

//--- 指标设置

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_plots   1

//--- 全局变量

double ExtDynamic[];   // 动态数组

double ExtStatic[100]; // 静态数组

bool   ExtFlag=true;   // 标识

double ExtBuff[];      // 指标缓冲区

//+------------------------------------------------------------------+

//| 自定义指标初始函数                                                 |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- 为数组分配内存

   ArrayResize(ExtDynamic,100);

//--- 指标缓冲区映射

   SetIndexBuffer(0,ExtBuff);

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| 自定义指标迭代函数                                                 |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const int begin,

                const double &price[])

  {

//--- 执行一个分析

   if(ExtFlag)

     {

      //--- 尝试释放数组内存

      //--- 1. 动态数组

      Print("+============================+");

      Print("1. Check dynamic array:");

      Print("Size before memory is freed = ",ArraySize(ExtDynamic));

      Print("Is this a dynamic array = ",ArrayIsDynamic(ExtDynamic) ? "Yes" : "No");

      //--- 尝试释放数组内存

      ArrayFree(ExtDynamic);

      Print("Size after memory is freed = ",ArraySize(ExtDynamic));

      //--- 2. 静态数组

      Print("2. Check static array:");

      Print("Size before memory is freed = ",ArraySize(ExtStatic));

      Print("Is this a dynamic array = ",ArrayIsDynamic(ExtStatic) ? "Yes" : "No");

      //--- 尝试释放数组内存

      ArrayFree(ExtStatic);

      Print("Size after memory is freed = ",ArraySize(ExtStatic));

      //--- 3. 指标缓冲区

      Print("3. Check indicator buffer:");

      Print("Size before memory is freed = ",ArraySize(ExtBuff));

      Print("Is this a dynamic array = ",ArrayIsDynamic(ExtBuff) ? "Yes" : "No");

      //--- 尝试释放数组内存

      ArrayFree(ExtBuff);

      Print("Size after memory is freed = ",ArraySize(ExtBuff));

      //--- 改变标识的值

      ExtFlag=false;

     }

//--- 为下次调用返回prev_calculated值

   return(rates_total);

  }

另见

接入时间序列和指标