Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.


14.4.2 Array allocation

Arrays can also be allocated using NEW, and this works in a very similar way to that outlined in the previous section. The difference is that the size of the array must also be supplied, in both the use of NEW and END. Of course, the size supplied to END must be the same as the size supplied to the appropriate use of NEW. All this extra effort also gains you the ability to create an array of a size which is not a constant (unlike variables of type ARRAY). This means that the size supplied to NEW and END can be the result of an arbitrary expression.

  DEF a:PTR TO LONG, b:PTR TO myobj, s
  NEW a[10]  /* A dynamic array of LONG  */
  s:=my_random(20)
  NEW b[s]   /* A dynamic array of myobj */
  /* ...some other code... */
  END a[10], b[s]

The my_random function stands for some arbitrary calculation, to show that s does not have to be a constant. This form of NEW can also be used as an expression, as before.


Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.