Datatype arrayAn array in ChaosPro is an ordered set of values (0 based) that you refer to with a name and an index, eventually more than one index, if using a multidimensional array. Each element in an array is a number of a specific datatype. There are two types of arrays in ChaosPro:
On declaring the array you have to specify at least the dimension and the datatype of the elements in the array. For example, you could have a one-dimensional array called First of all, you have to define an array: Arrays can be defined only on class level, not on function level. This restriction is due to performance reasons: This way ChaosPro doesn't have to bother with freeing the array memory, it's sufficient to free it at the end of the fractal calculation. Always keep in mind: Allocating and freeing array memory lasts very long! It needs about 1/2000 of a second (on my computer), which does not seem to be much. But if you allocate an array in the init section of a fractal and calculate the fractal at a size of 320x200, then this means that 320x200=64000 array allocations are carried out, thus needing 32 seconds!
An array is declared using one of the following syntax:
Examples:
d[4]=6; // syntax error: dimension of array is 2! d[3,4]=8; // OK: dimension of array is 2, it's allowed to assign a real number to a quaternion number! x=sin(d[5,6]); // error: Function sin() cannot be applied to quaternion numbers So you can see, declaring an array allows ChaosPro to do all necessary syntax checks.
This statement defines a static array: Each element in the array has the datatype complex. The array has three dimensions, you cannot redimension it during runtime. Each array dimension needs to be a constant value, so you can use the value of a parameter for each array dimension.
This code will work because parameters are treated as constants. But please note that ChaosPro will produce an error if you later on write to a parameter! Important Notes:ChaosPro does no bounds checking or any other checks! So it's your responsibility to ensure that you do not write to uninitialized arrays or write beyond the limits of the array! ChaosPro will most likely crash! If you write beyond the limits of the array then there may be program code. The fractal calculation could behave almost "normal", but perhaps the program code which was overwritten contained the routine for saving a fractal image. And as soon as you then save an image, (perhaps hours after having used an array), ChaosPro can crash! Allocating array storage for dynamic arrays:After having declared the array you can allocate a "storage area" for the elements of the array. You do this by using the "array" function: This function first checks whether there has already been assigned a storage area for the array. If yes, it will free the old storage area, all values in this (old) area are lost! After that the array function will allocate and assign the new storage area. Example: // assume the array d has been declared as array d[2] of complex; d = array(10,20); // allocates storage area // 10*20 elements can be stored in this array: // d[0,0]...d[9,19] d = array(10,20,30); // Syntax Error: array dimension is 2, you cannot specify three dimensions! dim1=15; dim2=25; d = array(dim1,dim2); // The parameters of the array function need not be constants, they can be variables as well. // So this statement would allocate an array with 15*25 elements.Memory needs of arrays If you plan to heavily work with arrays you should take care about how much memory the array actually needs. The array needs memory to hold all its elements, and each element (primitive datatype: bool, int, float, double, real, complex, quaternion) needs a well known amount of memory. An array aDist[320,200] needs memory for 320x200 = 64000 elements. If the primitive datatype of the array is:
|