Results 1 to 5 of 5

Thread: Oxygen - help on passing multidimensional array to sub...

  1. #1
    Member
    Join Date
    May 2012
    Location
    Predappio
    Age
    51
    Posts
    34
    Rep Power
    15

    Oxygen - help on passing multidimensional array to sub...

    Hi all, It's been a while since my last post, I hope you're all doing well.
    I have a problem passing a multidimensional array to an oxygen sub... like this

    'Oxygen source ( I have last one Version Oxygen and Thinbasic )
    ''''''''''''''''''''''''''''''''
    src="
    Sub CalcPoint(addre as long, byref RetV as Single) link #p3

    indexbase 1
    Dim as Single Pws(4,4,4) at addre ' seem dont work

    ''''' i make some math on points and return some values '''''
    RetV=(my values calculated)
    End Sub
    "

    'Thinbasic source
    '''''''''''''''''''''''''''''''''
    Dim Pw(4,4,4) as Single
    Dim RetV as Single

    ''''' i put data in this array

    ptrv=varptr(Pw(1,1,1))
    CalcPoint (ptrv,retV)

    ----------------------------

    With array single-dimensional oxygen sub work, but with multidimensional i can't get it to work...

    I hope someone can help me.
    Thank you!

    Oscar

  2. #2
    Hi Oscar,
    Oxygen fully supports multidimensional arrays, as of December 2022.

    I don't know whether the current thinBasic includes this version, so I attach it below.

    Oxygen.dll goes into your thinBasic\lib folder.

    thinBasic uses indexbase 1 in Column-Major order, in other words the minor steps come first.

    #minormajor 'thinBasic and Powerbasic mode
    indexbase 1
    overlay single v(4,4,4)
    @v=#v 'link to host variable v


    uses "oxygen"
    
    
    'SHARED VARIABLES
    '================
    
    
    dim as string src
    dim as single v(4,4,4)
    '
    'OXYGENBASIC SECTION
    '===================
    src="
    #minormajor 'thinBasic and Powerbasic mode
    indexbase 1
    overlay single v(4,4,4)
    @v=#v 'link to host variable v
    dim as long c,x,y,z
    for z=1 to 4
      for y=1 to 4
        for x=1 to 4
          c++
          v(x,y,z)=c 'fill 1 to 64
        next
      next
    next 
    "
    
    
    'COMPILE
    '=======
    
    
    o2_basic src
    if o2_errno then
      msgbox 0,o2_error
      stop
    else
      o2_exec
      'msgbox 0,"ok"
    end if
    
    
    
    
    'MAIN THINBASIC SECTION
    '======================
    
    
    'array Order: 17 18 19 20
    msgbox 0,"Order: "+v(1,1,2)+", "+v(2,1,2)+", "+v(3,1,2)+", "+v(4,1,2)
    
    Attached Files Attached Files
    Last edited by Charles Pegge; 15-03-2023 at 09:12.

  3. #3
    Member
    Join Date
    May 2012
    Location
    Predappio
    Age
    51
    Posts
    34
    Rep Power
    15
    Hi Charles,
    and thanks for the reply... Your work is amazing

    I had already seen the example in your other posts...
    I only wanted to know if it is possible to pass a multidimensional array or a pointer to this array as an argument, and "dim" a new multidimensional array inside the oxygen sub that points to array in the argument ...
    If it is not possible, in thinbasic using peek and poke I succeed, I will do as you wrote.
    Thank you

    Oscar

  4. #4
    Thanks Oscar,

    I've developed this example a bit more, and given O2 all the responsibility for creating and managing the array-space. The array-space is only freed when finish() is executed.

    You have to be careful about when variables are created on the thinBasic side.

    
    uses "oxygen"
    
    
    'SHARED VARIABLES
    '================
    
    
    dim as string src
    dim as long pCreateArray3d
    dim as long pFinish
    '
    'OXYGENBASIC SECTION
    '===================
    src="
    #minormajor 'thinBasic and Powerbasic mode
    indexbase 1
    redim single v(0,0,0)
    
    
    sub CreateArray3d(sys *pv, long x,y,z) link #pCreateArray3d
      redim single v(x,y,z)
      pv=@v 'link to host variable v
      dim as long c,x,y,z
      for z=1 to 4
        for y=1 to 4
          for x=1 to 4
            c++
            v(x,y,z)=c 'fill 1 to 64
          next
        next
      next
    end sub
    
    
    sub finish() link #pFinish
      freememory @v
      terminate
    end sub
    
    
    "
    
    
    'COMPILE
    '=======
    
    
    o2_basic src
    if o2_errno then
      msgbox 0,o2_error
      stop
    else
      o2_exec
      'msgbox 0,"ok"
    end if
    
    
    
    
    'MAIN THINBASIC SECTION
    '======================
    declare sub CreateArray3d(byref pv as long, byval x as long, byval y as long, byval z as long ) at pCreateArray3d
    declare sub Finish() at pFinish
    dim as long pv
    dim as long x,y,z
    x=4
    y=4
    z=4
    CreateArray3d(pv,x,y,z)
    'msgbox 0,pv
    dim as single v(x,y,z) at pv
    'array Order: 17 18 19 20
    msgbox 0,"Order: "+v(1,1,2)+", "+v(2,1,2)+", "+v(3,1,2)+", "+v(4,1,2)
    finish()
    

  5. #5
    Member
    Join Date
    May 2012
    Location
    Predappio
    Age
    51
    Posts
    34
    Rep Power
    15
    Thanks Charles!
    And sorry for the same questions every time!

    I will try it.
    Bye,
    Oscar

Similar Threads

  1. Multidimensional array limit???
    By Oscar Ugolini in forum thinBasic General
    Replies: 2
    Last Post: 20-10-2012, 13:09
  2. Oxygen Flexi Parameter Passing
    By Charles Pegge in forum O2h Compiler
    Replies: 14
    Last Post: 25-05-2010, 09:32
  3. passing a string from oxygen to vb6
    By zak in forum O2 JIT Compiler / Assembler / Oxygen project
    Replies: 0
    Last Post: 24-07-2009, 21:36

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •