Suppose that there is a multi-dim array as such: myarray(9,9,9).
To loop through each element:
Code: Select all
for i=0 to 9
for j=0 to 9
for k=0 to 9
'do something
next k
next j
next i
Code: Select all
for i=0 to 999
'do something
next i
Code: Select all
for i=0 to 9
for j=0 to 9
for k=0 to 9
'do something
next k
next j
next i
Code: Select all
for i=0 to 999
'do something
next i
Code: Select all
dim as integer ptr test=@myarray(0,0,0)
for i=0 to 999
*(test+i)=123
next i
Code: Select all
dim as long myarray(9,9,9)
dim as long i,j,k
for i=0 to 9
for j=0 to 9
for k=0 to 9
myarray(i,j,k)=i*j*k+rnd*6-rnd*6
next k
next j
next i
for i=0 to 9
for j=0 to 9
for k=0 to 9
print myarray(i,j,k);
next k
next j
next i
print
#macro Get_Size(array,d)
d=Ubound(array,0)
For n As long=1 To d
If n=1 Then d=1
d=d*(Ubound(array,n)-Lbound(array,n)+1)
Next
#endmacro
#macro memcopy(dest,src,size)
For n As Long=0 To size-1
(dest)[n]=(src)[n]
Next
#endmacro
dim as long sz
get_Size(myarray,sz)
print
print
dim as long c(1 to sz)
memcopy(@c(1),@myarray(0,0,0),sz)
for n as long=lbound(c) to ubound(c)
print c(n);
next n
print
sleep
Code: Select all
#include "crt.bi"
#include "fbc-int/array.bi"
dim as long myarray(9,9,9)
dim as long i,j,k
for i=0 to 9
for j=0 to 9
for k=0 to 9
myarray(i,j,k)=i*j*k+rnd*6-rnd*6
next k
next j
next i
for i=0 to 9
for j=0 to 9
for k=0 to 9
print myarray(i,j,k);
next k
next j
next i
print
dim as long ptr fbp=fb_ArrayGetDesc(myarray())->base_ptr
dim as long sz=fb_ArrayGetDesc(myarray())->size
dim as long size=fb_ArrayGetDesc(myarray())->element_len
sz\=size 'number of elements
print
print
dim as long c(1 to sz)
dim as long ptr cp=fb_ArrayGetDesc(c())->base_ptr
memcpy(cp,fbp,sz*size)
for n as long=lbound(c) to ubound(c)
print c(n);
next n
print
sleep
Not only.srvaldez wrote:try using FBC
Code: Select all
#include "crt.bi"
#include "fbc-int/array.bi"
dim as long myarray(9,9,9)
dim as long i,j,k
for i=0 to 9
for j=0 to 9
for k=0 to 9
myarray(i,j,k)=i*j*k+rnd*6-rnd*6
next k
next j
next i
for i=0 to 9
for j=0 to 9
for k=0 to 9
print myarray(i,j,k);
next k
next j
next i
print
dim as long ptr fbp=FBC.ArrayDescriptorPtr(myarray())->base_ptr
dim as long sz=FBC.ArrayDescriptorPtr(myarray())->size
dim as long size=FBC.ArrayDescriptorPtr(myarray())->element_len
sz\=size 'number of elements
print
print
dim as long c(1 to sz)
dim as long ptr cp=FBC.ArrayDescriptorPtr(c())->base_ptr
memcpy(cp,fbp,sz*size)
for n as long=lbound(c) to ubound(c)
print c(n);
next n
print
sleep
fxm wrote:Personally, I prefer the following syntax (with a pointer index), considering that the data to access is into an integer buffer pointed by test:
test = 123
dodicat wrote: rewriting the array to a single-dim