MQL4 Reference Language Basics Data Types Dynamic Array Object
Dynamic Array ObjectDynamic ArraysMaximum 4-dimension array can be declared. When declaring a dynamic array (an array of unspecified value in the first pair of square brackets), the compiler automatically creates a variable of the above structure (a dynamic array object) and provides a code for the correct initialization. Dynamic arrays are automatically freed when going beyond the visibility area of the block they are declared in. Example:
Static ArraysWhen all significant array dimensions are explicitly specified, the compiler pre-allocates the necessary memory size. Such an array is called static. Nevertheless, the compiler allocates additional memory for the object of a dynamic array, which (object) is associated with the pre-allocated static buffer (memory part for storing the array). Creating a dynamic array object is due to the possible need to pass this static array as a parameter to some function. Examples:
Arrays in StructuresWhen a static array is declared as a member of a structure, a dynamic array object is not created. This is done to ensure compatibility of data structures used in the Windows API. However, static arrays that are declared as members of structures can also be passed to MQL5 functions. In this case, when passing the parameter, a temporary object of a dynamic array will be created. Such an object is linked with the static array - member of structure. See also Array Functions, Initialization of Variables, Visibility Scope and Lifetime of Variables, Creating and Deleting Objects |