Shop OBEX P1 Docs P2 Docs Learn Events
Is there a maximum number of variable pointers that can be passed as parameters — Parallax Forums

Is there a maximum number of variable pointers that can be passed as parameters

4Alex4Alex Posts: 119
edited 2009-09-04 20:57 in Propeller 1
Good afternoon all,

I am passing variable pointers as parameters between objects.

In spin1, I do like this:

if test.start(@Status,@Data0,@Data1,@Data2,@Data3,@Data4,@Data5,@Data6,@Data7,@Data8,@Data9)
  test.run




In spin2, I do like this:

PUB start(Status,Data0,Data1,Data2,Data3,Data4,Data5,Data6,Data7,Data8,Data9) : okay | retValue
  StatusPtr := Status
  Data0Ptr := Data0
  Data1Ptr := Data1
  Data2Ptr := Data2
  .
  .
  Data9Ptr := Data9




This work well but if I add one more parameter, say Data10, the propeller becomes unreliable. I've tried increasing the stack but to no avail. Is there a limit to the number of parameters representing a variable pointer that can be passed?

Many thanks for any assistance.

Cheers,

Alex

Post Edited (4Alex) : 9/4/2009 10:00:41 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-04 19:54
    The only limit on the number of variable pointers as parameters is a limit on the total number of parameters in a call. I believe that's 15. If you're having a problem with your program it's likely to be due to stack overflow (not enough space available for the stack). Exceeding the allowed number of parameters results in a compilation error, not "becomes unreliabile". That is typical of not having enough stack space or passing the wrong pointer value.
  • 4Alex4Alex Posts: 119
    edited 2009-09-04 20:09
    @Mike:

    Thanks for your prompt reply. I am a bit confused about passing pointers, so I might have done something wrong.

    In the VAR section of spin1: byte Data0

    In the VAR section of spin2: byte Data0Ptr
    and then I change a value this way: byte[noparse][[/noparse]Data0Ptr] := 4

    My variable Data0 is definitely a byte but perhaps the variable Data0Ptr should be a long? BTW, what exactly is into Data0Ptr: my byte value or the pointer of Data0?

    Thanks for your help.

    Cheers,

    Alex

    Post Edited (4Alex) : 9/4/2009 8:17:20 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-04 20:34
    Pointers (like Data0Ptr) have to be at least a word in size. You can make them a long word if you want. The range of pointer values (addresses) is 0-65535.

    Again, you'd declare all the pointers like Data0Ptr as words and use the pointers the way your wrote (byte[noparse][[/noparse]Data0Ptr] := 4).

    Data0Ptr contains the hub address of the variable Data0.
  • 4Alex4Alex Posts: 119
    edited 2009-09-04 20:57
    @Mike:

    Great. Many thanks for your clear explaination. Now that makes sense.

    I have one additional question about the size of what I can pass:

    Could I pass a long instead of a byte? Would that work also with a byte array (like Data[noparse]/noparse]10] instead of Data0..Data9). If this is possible, could I just write something like byte[noparse][[/noparse]DataPtr[noparse][[/noparse]0 := 4 ? That would be great because I could use bytemove and bytefill.

    Cheers,

    Alex
Sign In or Register to comment.