Is there a maximum number of dimensions to an array?

New to FreeBASIC? Post your questions here.
RayTomes
Posts: 36
Joined: Mar 13, 2008 20:18
Location: Auckland, New Zealand
Contact:

Is there a maximum number of dimensions to an array?

Postby RayTomes » Mar 14, 2008 7:26

To learn about freebasic I was trying out some programs that I wrote in CSC (Corel Script Language) which is very similar to QBASIC (withe knobs on).
I tried a program which has a 9 dimensional array (yes really 9) and it complained that I had too many subscripts (starting from the bottom of the program and working up). So I knocked out one dimension and it now works. Note that it had 18 nested FOR ... NEXT loops also.

I cannot see anything in the documentation about any limits on the number of dimensions. Does anyone know if there is a limit? If this had worked well I was thinking of going for about an 11 dimensional array. :-)
RayTomes
Posts: 36
Joined: Mar 13, 2008 20:18
Location: Auckland, New Zealand
Contact:

Postby RayTomes » Mar 14, 2008 7:29

Oh, I just saw in the documentation that it says:
"The maximum number of dimensions of a multidimensional array is 8. "

Oh damn, why do they make limits like this?
integer
Posts: 390
Joined: Feb 01, 2007 16:54
Location: usa

Postby integer » Mar 14, 2008 8:02

Just curious, but what you are doing that requires 11 dimensions?

Most of the arrays I use rarely have more than three dimensions.
When more than five are required, the arrays become extremely sparse, and it is easier to tag the elements.

If you have a modest 10 elements per dimension, your 11 dimension array would require about 200 GIG of space (200 billion bytes).

If you really require more dimensions, then create your own UDT.
When you require a specific element, access it through your defined type.

It is unlikely that you have more than a 1000 gigabytes of random access memory, thus the necessity for file access.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Mar 14, 2008 8:13

I never use an array more than one dimension. I hate multidimensional arrays with a passion. I don't mind arrays of arrays (ex Java), but multidimensional, sequential arrays?

I really prefer pointers and some simple math instead.


However! ... I don't like the artificial limits. I only like being limited when I absolutely have to be, due to technical challenges, for instance.
HD_
Posts: 215
Joined: Jun 10, 2006 12:15
Contact:

Postby HD_ » Mar 14, 2008 8:39

Multi-dimensional arrays make code more readable, eg:
tiles(layer,x,y)
But 9 or 11 dimensions is just insane. If I was to try to expand the above to as many dimensions as I could:
tiles(universe,galaxy,planet,computer,program,room,layer,x,y,phosphor,atom)

There, 11 dimensions to fully describe a unit in a game on any computer in any world in any galaxy in any universe. What are you using it for?
RayTomes
Posts: 36
Joined: Mar 13, 2008 20:18
Location: Auckland, New Zealand
Contact:

Postby RayTomes » Mar 14, 2008 9:32

Well, I am calculating the number of ways that each number with many factorizations can be factorized. I have done up to 10^53 so far but want to go a bit further. The easiest way is to represent each number as its prime factorization:

n = 2^a 3^b 5^c 7^d 11^e 13^f 17^g 19^h 23^i ...

The number of ways it can be factorized depends directly on the coefficients a,b,c,d,e,f,g,h,i ... so I have a table with that many dimensions. Some of the dimensions only have a small range but it still makes quite a big array.

See http://ray.tomes.biz/maths.html if you want to know why I do this. :-)
actuall HD_'s description is too far out. ;-)

I can combine several indexes into one and still do what I want.
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: Is there a maximum number of dimensions to an array?

Postby Luis Babboni » Jul 07, 2015 13:02

Hello,

I´m in the same trouble. I need up to 10 dimensions for making an stat about chess.
Cause may be I will need tht stat in real time, is important for me the time access I will have and using Allocate seems is by far much slower than using arrays..... so I ´m perplexed :-/
St_W
Posts: 1494
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Is there a maximum number of dimensions to an array?

Postby St_W » Jul 07, 2015 15:02

I don't know whether that's a technical limit or just a defined limit, but you may try setting the following #define to some higher value and recompile fbc:

Code: Select all

' in src/compiler/fb.bi
const FB_MAXARRAYDIMS       = 8

see https://github.com/freebasic/fbc/blob/m ... /fb.bi#L33

dkl can probably give a hint whether that would work or not and whether this causes any side-effects.
grindstone
Posts: 726
Joined: May 05, 2015 5:35
Location: Germany

Re: Is there a maximum number of dimensions to an array?

Postby grindstone » Jul 07, 2015 15:07

Luis Babboni wrote:Allocate seems is by far much slower than using arrays..... so I ´m perplexed :-/
It's not so surprising, for the array handling has been optimized for years.
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: Is there a maximum number of dimensions to an array?

Postby Luis Babboni » Jul 07, 2015 18:27

What about this suggestion from St_W he made in the same question I did here:
http://www.freebasic.net/forum/viewtopi ... =2&t=10920

St_W wrote:I don't know whether that's a technical limit or just a defined limit, but you may try setting the following #define to some higher value and recompile fbc:

Code: Select all

' in src/compiler/fb.bi
const FB_MAXARRAYDIMS       = 8

see https://github.com/freebasic/fbc/blob/m ... /fb.bi#L33

dkl can probably give a hint whether that would work or not and whether this causes any side-effects.
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: Is there a maximum number of dimensions to an array?

Postby Luis Babboni » Jul 07, 2015 18:29

Thanks guys, actually are the same question in two threads.
Interesting what St_W suggest! :-)
This answer, in some level, my question did in the other post grindstone :-)
fxm
Posts: 9700
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Is there a maximum number of dimensions to an array?

Postby fxm » Jul 07, 2015 20:31

There is a similar limitation on the number of levels of pointer indirection:
Maximum is:
p[n1][n2][n3][n4][n5][n6][n7][n8]
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Is there a maximum number of dimensions to an array?

Postby sancho2 » Jul 08, 2015 3:00

HD_ wrote:Multi-dimensional arrays make code more readable, eg:

tiles(layer,x,y)

But 9 or 11 dimensions is just insane. If I was to try to expand the above to as many dimensions as I could:

tiles(universe,galaxy,planet,computer,program,room,layer,x,y,phosphor,atom)



There, 11 dimensions to fully describe a unit in a game on any computer in any world in any galaxy in any universe. What are you using it for?


Haven't you described an object though?

Code: Select all

Type TileType
      layer As Integer
      x As Integer
      y As Integer
End Type

Type SuperTile extends TileType
   universe As Any Ptr
   galaxy As Any Ptr
   planet As Any Ptr
   computer As Any Ptr
   program As Any Ptr
   room As Any Ptr
   phosphor As Any Ptr
   atom As Any Ptr
End Type

Dim myTile As SuperTile

myTile.Layer = 1
myTile.universe = ?


Even more readable?
RockTheSchock
Posts: 230
Joined: Mar 12, 2006 16:25

Re: Is there a maximum number of dimensions to an array?

Postby RockTheSchock » Jul 08, 2015 8:12

EDIT:
I would suggest to use x,y coordinates as relative coordinates. So your galaxy cordinates are relative to the universe center. Planet coords are relative to the galaxy center and so on.

Code: Select all

Type TileType
   title As String   
   x As Integer
   y As Integer
   parent As TileType Ptr
End Type


Type AtomType As Integer

Type PhosphorType extends TileType
   atom(Any) As AtomType
End Type

Type RoomType extends TileType
   phosphor(Any) As PhosphorType
End Type

Type ProgramType extends TileType
   room(Any) As RoomType
End Type

Type ComputerType extends TileType
   program(Any) As ProgramType   
End Type


Type PlanetType extends TileType
   computer(Any) As ComputerType   
End Type


Type GalaxyType extends TileType      
   planet(Any) As PlanetType   
End Type

Type UniverseType extends TileType   
   Declare Constructor()                       'Create empty universe
   Declare Constructor(seed As Double=-1.0)   'Create random universe using seed / defaults to Randomize Timer
   galaxy(Any) As GalaxyType   
End Type

Constructor UniverseType()
   ReDim Preserve galaxy(1 To 100) ' create 100 empty galaxies
End Constructor

Constructor UniverseType(seed As Double=-1.0)
End Constructor

Dim universe(1 To 11) As UniverseType
sleep
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Is there a maximum number of dimensions to an array?

Postby sancho2 » Jul 09, 2015 2:02

RockTheSchock wrote:EDIT:
I would suggest to use x,y coordinates as relative coordinates. So your galaxy cordinates are relative to the universe center. Planet coords are relative to the galaxy center and so on.

Very nice RockTheShock. It makes a guy want to continue the program.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests