I posted an example to use the array descriptor.
All that fear of incompatibility!
If it changes, you simply adapt to that compiler ain't it?
We are programmer's
This looks much of the same fear of using callbacks in VB.
Spooookkyyy!
On my site in the freetips help, you can find a copy of that source.
------------------
[email protected]
Announcement
Collapse
No announcement yet.
Ubound of a Index Pointer
Collapse
X
-
I'm just wanting to make one function that I can call with
1 parameter that is a long or dword that will point to the
address of the array and I wish to find the ubound of that
pointer.
(That is, in a factory-supported manner).
It can be done with the PB/DOS compilers using the internal functions ArrayCalc and ArrayInfo.
MCM
Leave a comment:
-
Greg --
Probably, this code explains you better, how PB (and not only it) passes arrays.
Each array (like a string, for example), has a descriptor, which describes dimensions, location and so on.
When you use A(), PB simply transfers VarPtr to descriptor, which already exist before CALL.
So for performance this is equal to transfer scalar variable.
To demonstrate this, I included "hooligan action" and as you can see, LBound eats new "information".
Code:#Compile Exe ' DO NOT USE SUCH WAY Function Bounds1 (Ar() As Long) As Long ReDim Arr(0) As Dword At VarPtr(Ar()) MsgBox Format$(Arr(6), "LBOUND = # ") + $CRLF + _ Format$(Arr(7), "UBOUND = # ") + $CRLF + _ Format$(Arr(0), "At = #"), , "Variant 1" Arr(6) = 1752 ' hooligan action End Function ' USE THIS WAY Function Bounds2 (Ar() As Long) As Long MsgBox Format$(LBound(Ar()), "LBOUND = # ") + $CRLF + _ Format$(UBound(Ar()), "UBOUND = # ") + $CRLF + _ Format$(VarPtr(Ar(LBound(Ar()))), "At = #"), , "Variant 2" End Function Function PbMain Dim A(705 To 1425) As Long Bounds1 A() Bounds2 A() End Function
Leave a comment:
-
Lance,
I guess I'm just wanting to use pointers because I assume it's
faster. The main reason I'm just simply wanting to pass
the dword address to the function is so its easier to call from
VB.
I don't really understand Semen's example. To me it looks like
common sense but you talk about descriptors?
I'm just wanting to make one function that I can call with
1 parameter that is a long or dword that will point to the
address of the array and I wish to find the ubound of that
pointer.
------------------
-Greg
Leave a comment:
-
I know I could simple pass the ubound to the function as well or
have it global but I really don't want to do that. Any ideas?
Regardless, I don't see why is it so important to avoid using the methods that PowerBASIC currently provides to work with arrays in Subs/Functions. Maybe I'm missing something...?
As an aside, it is likely that a future version of PowerBASIC will include facilities to programmatically query array descriptor information, but that will likely require access to the array descriptor too.
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Leave a comment:
-
I prefer descriptors
Code:#Compile Exe Function Bounds (Ar() As Long) As Long MsgBox Format$(LBound(Ar()), "LBOUND = # ") + $CRLF + _ Format$(UBound(Ar()), "UBOUND = # ") + $CRLF + _ Format$(VarPtr(Ar(LBound(Ar()))), "At = #") End Function Function PbMain Dim A(5 To 25) As Long Bounds A() End Function
Leave a comment:
-
Ubound of a Index Pointer
How do I find the ubound of an index pointer without passing it
to a function?
eg.
Code:function example(address as dword) export as single ArrayPTR = Address Ubound& = <--------------------- How do I get this? for next a = 0 to ubound& ... ... next end function function pbmain() as long a! = example(VARPTR(ArrayIn(0)) end function
have it global but I really don't want to do that. Any ideas?
Thanks
------------------
-GregTags: None
Leave a comment: