Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Three-dimensional array
#21
Quote:This is for sanity reasons. Otherwise a programmer "for hobby" is going to want to change the extent of one of the dimensions as well which is a nightmare to maintain on the developer's side.
I agree that using a stack structure for array it is so impossible to put into the array new items among those already standing there with a simply copy of ram.
So you must copy the first dimension from the first to the last item, then add void cell for the new items and repeat this block of operations for all the dimensions of the array.


copy the items of dimension to new memory --> set to void (0 or nullstring) the following memory for the new items ---|
^                                                                                                                                                                       v
|-------------------------------------------------------------------------------------------------------------------------------------------------|

In a stack structure you must not simply copy the block of ram and add on it... it is possible only for the last index of a multidimensional array because , as Steve pointed out, after the last item of the last dimension there is nothing and so you do not modify the index.

Moreover if now you REDIM an array changing the indexes  (lower and upper) but not the range, the data will be again in order...the second output of the example, if you REDIM the same array lowering the index of start your data will run down to populate the earlier items, see the third output of example:
  

Code: (Select All)
REDIM a(1 to 4) : a(1) = 1 : a(2) = 2: a(3)=3: a(4)=4
for x = 1 to 4 
  print  a(x);" - ";
next x
print " / "


REDIM _Preserve a(10 to 14) 
for x = 10 to 14 
  print  a(x);" - ";
next x
print " / "

redim _Preserve a(1 to 14)
for x = 1 to 14 
  print  a(x);" - ";
next x
print " / "

These are the features of the array in BASIC. I dunno if there is a PRESERVE function in other procedural languages and if it is different from that of BASIC.
Reply




Users browsing this thread: 1 Guest(s)