No more than 8 dimensions in Array! :-(

New to FreeBASIC? Post your questions here.
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 06, 2015 21:43

Hello.

I need an array with 12 indexes but if I try to dim more than 8 its says "too many array dimensions" :-(
Any suggestion?
May be is possible, and may be faster, to directly place information in memory but not know how to do it.

Thanks in advance.
Last edited by Luis Babboni on Jul 06, 2015 22:14, edited 2 times in total.
bcohio2001
Posts: 552
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: No more than 8 indexes in Array! :-(

Postby bcohio2001 » Jul 06, 2015 21:48

Dim A(11) As Integer
or
Dim A(1,2,3,4,5,6,7,8,9,10,11,12) As Integer

Which one, first one is 12 indexes and second is 12 dimensions?
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 indexes in Array! :-(

Postby Luis Babboni » Jul 06, 2015 22:12

bcohio2001 wrote:Dim A(11) As Integer
or
Dim A(1,2,3,4,5,6,7,8,9,10,11,12) As Integer

Which one, first one is 12 indexes and second is 12 dimensions?


Sorry, second one.
I´m trying with Callocate, not sure if the correct option.
I tried Callocate and not Allocate cause I need the values not loaded with values remains as 0. I did the correct election?

Thanks.

PS: subject edited.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: No more than 8 dimensions in Array! :-(

Postby vdecampo » Jul 06, 2015 22:52

You do realize that the array as you show in your example uses over 1.9Gb of memory?

-Vince
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: No more than 8 indexes in Array! :-(

Postby sancho2 » Jul 07, 2015 1:09

Luis Babboni wrote:12 dimension arrray

It sounds to me like you are in need of nested types.
It's not often you see more than 3 dim array. I can't imagine the use case for 12.
Could you elaborate a little on what you are using it for?
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 1:29

vdecampo wrote:You do realize that the array as you show in your example uses over 1.9Gb of memory?

-Vince


Do not scared me!! :-D The example is not mine array.
Mine is A(9,3,3,3,2,9,3,3,3,2)* as integer that have, if i´m right, 9^2*3^6*2*2 bytes = 236,196 bytes = 230KB

I´m trying to make stats about combinations of amount of material in chess:
0 to 8 white pawns; 0 to 2 white knights; 0 to 2 white bishops; 0 to 2 white rooks and 0 to 1 white queen and the same for black pieces.

*In fact just 10 dimensiosn, not 12 as I thought first.
dodicat
Posts: 6557
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: No more than 8 dimensions in Array! :-(

Postby dodicat » Jul 07, 2015 2:57

To get 10 dimensions artificially I have created an array of one dimension to hold the values.

Up to 20 fake dimensions are coded for here.

I have used the 10 dimension sizes given:

Code: Select all

'up to 20 fake dimensions
#define _r(n) (ub(n)-lb(n)+1)
#define d1(n1) (n1-lb(1))
#define d2(n1,n2) (_r(2)*d1(n1)+(n2-lb(2)))
#define d3(n1,n2,n3) (_r(3)*d2(n1,n2)+(n3-lb(3)))
#define d4(n1,n2,n3,n4) (_r(4)*d3(n1,n2,n3)+(n4-lb(4)))
#define d5(n1,n2,n3,n4,n5) (_r(5)*d4(n1,n2,n3,n4)+(n5-lb(5)))
#define d6(n1,n2,n3,n4,n5,n6) (_r(6)*d5(n1,n2,n3,n4,n5)+(n6-lb(6)))
#define d7(n1,n2,n3,n4,n5,n6,n7) (_r(7)*d6(n1,n2,n3,n4,n5,n6)+(n7-lb(7)))
#define d8(n1,n2,n3,n4,n5,n6,n7,n8) (_r(8)*d7(n1,n2,n3,n4,n5,n6,n7)+(n8-lb(8)))
#define d9(n1,n2,n3,n4,n5,n6,n7,n8,n9) (_r(9)*d8(n1,n2,n3,n4,n5,n6,n7,n8)+(n9-lb(9)))
#define d10(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10) (_r(10)*d9(n1,n2,n3,n4,n5,n6,n7,n8,n9)+(n10-lb(10)))
#define d11(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11) (_r(11)*d10(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10)+(n11-lb(11)))
#define d12(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12) (_r(12)*d11(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11)+(n12-lb(12)))
#define d13(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13) (_r(13)*d12(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)+(n13-lb(13)))
#define d14(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14) (_r(14)*d13(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13)+(n14-lb(14)))
#define d15(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15) (_r(15)*d14(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14)+(n15-lb(15)))
#define d16(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16) (_r(16)*d15(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15)+(n16-lb(16)))
#define d17(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17) (_r(17)*d16(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16)+(n17-lb(17)))
#define d18(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18) (_r(18)*d17(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17)+(n18-lb(18)))
#define d19(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19) (_r(19)*d18(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18)+(n19-lb(19)))
#define d20(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19,n20) (_r(20)*d19(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19)+(n20-lb(20)))
dim as integer d=10 'dimensions required

dim as ulongint lb(1 to d),ub(1 to d) 'lower and upper bound arrays defined here

'set up fake lower and upper bounds
''A(9,3,3,3,2,9,3,3,3,2) YOUR BOUNDS
for z as integer=1 to d
    select case z
    case 1,6:    lb(z)=0:ub(z)=9
    case 2,3,4,7,8,9:    lb(z)=0:ub(z)=3
    case 5,10:    lb(z)=0:ub(z)=2
    end select
    next z
'use a real array to test method
print "Test against an array dim 7" 'fake versus real
dim as integer b(9,3,3,3,2,9,3) 'the first seven of Yours
print d7(9,3,3,3,2,9,3)
print @b(9,3,3,3,2,9,3)-@b(0,0,0,0,0,0,0)
print d7(0,0,0,0,0,0,0)
print "_______________________________"
print

var x=d10(9,3,3,3,2,9,3,3,3,2)'set up 10 fake dimensions
print "d10 = ";x

dim shared as integer a(0 to x)'get a single dimension array equivelant

dim as integer n1,n2,n3,n4,n5,n6,n7,n8,n9,n10
dim as integer counter
for n1=0 to 9
    for n2=0 to 3
        for n3=0 to 3
            for n4=0 to 3
                for n5=0 to 2
                    for n6=0 to 9
                        for n7=0 to 3
                            for n8=0 to 3
                                for n9=0 to 3
                                    for n10=0 to 2
                      'get some values                           
              a( d10(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10) )=counter                                 
                 counter+=1                               
next:next:next:next:next:next:next:next:next:next

'alternative way to fill
for z as integer=0 to x
    'a(z)=z
next z
'--------------------

print a(d10(9,3,3,3,2,9,3,3,3,2))'top value
print a(d10(3,0,3,2,1,2,3,2,1,0))'somewhere in the middle
print a(d10(0,0,0,0,0,0,0,0,0,0))'lowest value
sleep
caseih
Posts: 1505
Joined: Feb 26, 2007 5:32

Re: No more than 8 dimensions in Array! :-(

Postby caseih » Jul 07, 2015 3:02

Luis Babboni wrote:Mine is A(9,3,3,3,2,9,3,3,3,2)* as integer that have, if i´m right, 9^2*3^6*2*2 bytes = 236,196 bytes = 230KB


Close. I think it would be 236196 * sizeof(integer). So 1 or 2 MB depending on 32 or 64-bit.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: No more than 8 dimensions in Array! :-(

Postby vdecampo » Jul 07, 2015 3:10

Luis Babboni wrote:
vdecampo wrote:You do realize that the array as you show in your example uses over 1.9Gb of memory?

-Vince


Do not scared me!! :-D The example is not mine array.
Mine is A(9,3,3,3,2,9,3,3,3,2)* as integer that have, if i´m right, 9^2*3^6*2*2 bytes = 236,196 bytes = 230KB

I´m trying to make stats about combinations of amount of material in chess:
0 to 8 white pawns; 0 to 2 white knights; 0 to 2 white bishops; 0 to 2 white rooks and 0 to 1 white queen and the same for black pieces.

*In fact just 10 dimensiosn, not 12 as I thought first.


I calculate 839,608 x SizeOf(Integer) which is about 3.4 Mb.

-Vince
dodicat
Posts: 6557
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: No more than 8 dimensions in Array! :-(

Postby dodicat » Jul 07, 2015 3:17

OOPS.
I see that your actual dimension sizes are one less (0 to ...)
So caseih is correct.
I have re-done:

Code: Select all

 
'up to 20 fake dimensions
#define _r(n) (ub(n)-lb(n)+1)
#define d1(n1) (n1-lb(1))
#define d2(n1,n2) (_r(2)*d1(n1)+(n2-lb(2)))
#define d3(n1,n2,n3) (_r(3)*d2(n1,n2)+(n3-lb(3)))
#define d4(n1,n2,n3,n4) (_r(4)*d3(n1,n2,n3)+(n4-lb(4)))
#define d5(n1,n2,n3,n4,n5) (_r(5)*d4(n1,n2,n3,n4)+(n5-lb(5)))
#define d6(n1,n2,n3,n4,n5,n6) (_r(6)*d5(n1,n2,n3,n4,n5)+(n6-lb(6)))
#define d7(n1,n2,n3,n4,n5,n6,n7) (_r(7)*d6(n1,n2,n3,n4,n5,n6)+(n7-lb(7)))
#define d8(n1,n2,n3,n4,n5,n6,n7,n8) (_r(8)*d7(n1,n2,n3,n4,n5,n6,n7)+(n8-lb(8)))
#define d9(n1,n2,n3,n4,n5,n6,n7,n8,n9) (_r(9)*d8(n1,n2,n3,n4,n5,n6,n7,n8)+(n9-lb(9)))
#define d10(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10) (_r(10)*d9(n1,n2,n3,n4,n5,n6,n7,n8,n9)+(n10-lb(10)))
#define d11(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11) (_r(11)*d10(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10)+(n11-lb(11)))
#define d12(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12) (_r(12)*d11(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11)+(n12-lb(12)))
#define d13(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13) (_r(13)*d12(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12)+(n13-lb(13)))
#define d14(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14) (_r(14)*d13(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13)+(n14-lb(14)))
#define d15(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15) (_r(15)*d14(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14)+(n15-lb(15)))
#define d16(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16) (_r(16)*d15(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15)+(n16-lb(16)))
#define d17(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17) (_r(17)*d16(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16)+(n17-lb(17)))
#define d18(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18) (_r(18)*d17(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17)+(n18-lb(18)))
#define d19(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19) (_r(19)*d18(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18)+(n19-lb(19)))
#define d20(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19,n20) (_r(20)*d19(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14,n15,n16,n17,n18,n19)+(n20-lb(20)))
dim as integer d=10 'dimensions required

dim as ulongint lb(1 to d),ub(1 to d) 'lower and upper bound arrays defined here

'set up fake lower and upper bounds
''A(8,2,2,2,1,8,2,2,2,1) YOUR BOUNDS
for z as integer=1 to d
    select case z
    case 1,6:    lb(z)=0:ub(z)=8
    case 2,3,4,7,8,9:    lb(z)=0:ub(z)=2
    case 5,10:    lb(z)=0:ub(z)=1
    end select
    next z
'use a real array to test method
print "Test against an array dim 7" 'fake versus real
dim as integer b(8,2,2,2,1,8,2) 'the first seven of Yours
print d7(8,2,2,2,1,8,2)
print @b(8,2,2,2,1,8,2)-@b(0,0,0,0,0,0,0)
print d7(0,0,0,0,0,0,0)
print "_______________________________"
print

var x=d10(8,2,2,2,1,8,2,2,2,1)'set up 10 fake dimensions
print "d10 = ";x
print (X+1); " * sizeof(integer) would be memory used here"
dim shared as integer a(0 to x)'get a single dimension array equivelant

dim as integer n1,n2,n3,n4,n5,n6,n7,n8,n9,n10
dim as integer counter
for n1=0 to 8
    for n2=0 to 2
        for n3=0 to 2
            for n4=0 to 2
                for n5=0 to 1
                    for n6=0 to 8
                        for n7=0 to 2
                            for n8=0 to 2
                                for n9=0 to 2
                                    for n10=0 to 1
                      'get some values                           
              a( d10(n1,n2,n3,n4,n5,n6,n7,n8,n9,n10) )=counter                                 
                 counter+=1                               
next:next:next:next:next:next:next:next:next:next

'alternative way to fill
for z as integer=0 to x
    'a(z)=z
next z
'--------------------

print a(d10(8,2,2,2,1,8,2,2,2,1))'top value
print a(d10(3,0,2,2,1,2,0,2,1,0))'somewhere in the middle
print a(d10(0,0,0,0,0,0,0,0,0,0))'lowest value
sleep
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 4:38

Sizeof(Integer) Good point!
I could define integer<x> with x=8;16;32 or 64, I´m right? That is 1, 2, 4, 8 bytes respectevely, isn´t it?

What about to use Callalocate?
If I´m right, value of A(2,3,4)= value allocated in origin of allocation + 2*3*4 or something similar.
Works?
Is faster than arrays, the same or slower?
grindstone
Posts: 737
Joined: May 05, 2015 5:35
Location: Germany

Re: No more than 8 dimensions in Array! :-(

Postby grindstone » Jul 07, 2015 7:48

A 32 bit variable claims 4 bytes of memory space, no matter if in an array or in an allocated memory block. Also an array is quite the fastest way to handle a big amount of data, combined with a convenient access management. I would strongly recommend to use an array. To save memory space, you could think about using a different data type ('Byte' or 'Short').

Regards
grindstone
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 11:18

grindstone wrote:A 32 bit variable claims 4 bytes of memory space, no matter if in an array or in an allocated memory block. Also an array is quite the fastest way to handle a big amount of data, combined with a convenient access management. I would strongly recommend to use an array. To save memory space, you could think about using a different data type ('Byte' or 'Short').

Regards
grindstone


How to test it?
Timer is too gross, measures time in seconds :-(
grindstone
Posts: 737
Joined: May 05, 2015 5:35
Location: Germany

Re: No more than 8 dimensions in Array! :-(

Postby grindstone » Jul 07, 2015 11:39

Are you coding in QBasic?
Luis Babboni
Posts: 303
Joined: Mar 15, 2015 12:41

Re: No more than 8 dimensions in Array! :-(

Postby Luis Babboni » Jul 07, 2015 12:15

grindstone wrote:Are you coding in QBasic?


No, no, in FB.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 6 guests