You can use the sizeof operator to get the size of the array in bytes. You could then divide by four (four bytes holds an integer or long) or eight (for a float) to get the number of elements. If the array contains strings, then the above won't work since strings are not a standard size in ASPECT.
As I understand it Aspect does not allow for truely dynamic arrays. So you really just have to:
1. Dimension your array plenty large when you first define it.
* Note that if you like to keep your variables locals like Computer Sci types push you'll run into a problem of limited memory space reserved by Procomm.
* The cure for that is to make large arrays global as global variables are sent to a less restricted space.
2. You could write your own quasi-dynamic allocation routine using the conditional compilation and compiling from within a running script.
(probably not worth the bother)
If you are interested in knowing how many elements of the array have been actively used at some point in your program that is something your own code will have to do.
A suggestion is to have a counter, integer variable, to increment decrement as array elements are utilized.
Another convention that you could implement for integer arrays would be to designate the element [0] as your counter for that purpose. Just need to dimension one larger than otherwise needed and use the array like it is [1] based. If you don't like having an offset between a 1 based convention and a zero based array this can make things clearer without any significant problems...Even if you don't track the array use using [0].
Another way to determine if elements are used would be to initialize all elements with a value that would not be otherwise used -1, 0, integer's maximum or minimum value (which would effectively reduce the max or min by one in that case) either define the value as NL or MT or make it a global variable of that value. Then you can refer to it much the same as EOF is referred to in file access or NULL is sometimes used when looking at strings.
ie.
#define MT -2147483648
myArray[10001] ; 10000 array elements using it [1] based
proc main
integer cntr
for cntr = 0 UPTO 10001 BY 1
myArray[cntr] = MT
endfor
myArray[0] = 0 ; no array elements not empty
if myArray[2] == MT
termwrites "myArray[2] is empty"
endif
endproc
If you are just saying there is a number you have setup your script to accommodate a number of array elements say 20. Instead of hard coding the array size throughout,
try:
Then anywhere where you need an array based on the arraylimit size you just use arrayLimit.
Then if you need to make it bigger all you have to change is the arrayLimit variable and recompile.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.