I have searched but didn't reach to any conclusion that when I defined a sparse array does it reserve all the contiguous memory upto maximum index or it allocate the memory at that particular index only.array[100000]=ID1array[1001]=ID2Similarly when I do for loop for an array does it scan all the indexes where array[i] exists or it point only defined array's index for ex. 100000 & 1001. for(i in array){...}I have to store some value at specific index but I am afraid of memory allocation, so it become so much important for me to know: how does it actually allocate memory in case of sparse array?
Memory allocation for sparse array in awk
awk;memory;array
Per the gawk manual, which is a good general awk language reference:An important aspect to remember about arrays is that array subscripts are always strings.That is, awk arrays are always associative, and numeric keys are stringified. Only the keys that are in use are stored in the array (and maybe some extra space for the future). Numeric indices are not contiguous, so sparse arrays don't take up any more space than another array with the same number of elements.As for loops, when using the for (k in array) {body} syntax the:loop executes body once for each index in array that the program has previously usedAgain, only the indices that have been used will be included in the array iteration. Note that the order of iteration is undefined, however; it's not necessarily either numeric or the order of addition to the array.