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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple text pixel data to array demo Unseen Machine 5 653 09-12-2025, 05:30 PM
Last Post: bplus
  Unique Random Array Program eoredson 5 834 07-10-2025, 10:29 AM
Last Post: DANILIN
  QB64_GJ_LIB ARRay Library grymmjack 3 964 08-21-2023, 12:50 PM
Last Post: mnrvovrfc
  An hash array dictonary step by step TempodiBasic 32 8,148 05-08-2023, 06:12 PM
Last Post: TempodiBasic
  Get Next Filename into a string (or array) GTC 2 820 02-26-2023, 12:51 PM
Last Post: GTC

Forum Jump:


Users browsing this thread: 1 Guest(s)