Unlike other languages, in Chapel there is no allocate or new syntax to allocate arrays on the heap, but rather the usual "declaration" syntax. For example, in the following code, I “declare” two arrays A and B in a function based on formal (dummy) arguments:
proc test( n, D ) { var A: [1..n] real; // local array var B: [D] real; // local array writeln( "A.domain = ", A.domain ); writeln( "B.domain = ", B.domain ); } test( 3, {2..5} ); // request small arrays test( 10**7, {-10**7..10**7} ); // request large arrays
This gives the following result:
A.domain = {1..3} B.domain = {2..5} A.domain = {1..10000000} B.domain = {-10000000..10000000}
Due to the absence (despite the large size of B ), is it possible to assume that the above syntax always allocates A and B on the heap regardless of their size?
In addition, the assignment (or reassignment) of a domain variable, apparently, plays the role of distribution (or redistribution) of the array. For example, the following code works as expected. In this case, the distribution always occurs on the heap (again)?
var domC: domain(1); var C: [domC] real; writeln( "C = ", C ); domC = { 1..3 };
Result:
C = C = 7.0 7.0 7.0 C = 0.0 0.0 7.0 7.0 7.0 0.0 0.0
Finally, does the user need to use deallocate or delete these arrays manually, but does the system automatically free them if necessary?