en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en nl en en fa en en en he en en en en en en en en en en en en en en en en ca en en en en en nl en en de en en en en en en en en fr en da en en en en de en en en fr en en en en en en en en en pt en en en en en en
By logging into your account, you agree to our Privacy Policy, personal data processing and storage practices as described therein.
Forgot password or user name?
Search in titles only Search in PowerBASIC for Windows only
You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
All Time Today Last Week Last Month
All Discussions only Photos only Videos only Links only Polls only Events only
Join Date: Mar 2002
Array descriptor address (PB9)
5 Jul 2009, 08:21 AM
In 2005, Eric Cochran posted a thread called Yes, You CAN Redim Arrays Via A Ptr To Their Descriptor... in the source code forum.
A reply to the initial message implied that this could be a mistake.
However, in the PB8 and PB9 help, it states:
VARPTR may also be used to locate an array descriptor, as well as the array data itself. To find the address of an array descriptor, use the array name with empty parentheses: VARPTR( x( ) ).
When a REDIM statement is executed, the location of the array elements always moves in memory; however, the array's Descriptor location (VARPTR(arrayname()) will remain fixed at the original location.
I have found this to be a useful technique (i.e. passing array data and meta-data to generic forms) and have had no problems using this. However, I am interested if anyone else has found related issues.
To obtain the array descriptor address, use the following syntax as per the help text:
'Local hPtr As   Ptr 'hPtr = VarPtr(MyArray()) ' e.g. Local MyArray() As String Local hPtr As String Ptr ReDim MyArray(5) hPtr = VarPtr(MyArray())
Here is a sample of its use, using a string array. It works with other data types, including UDT's.
' test array descriptor address. Compiler: PB9 #Compile Exe #Dim All Function TestStr(aData() As String) As Long ' test string array descriptor ' aData(): parameter is ByRef, but pass array address descriptor value as ByVal ' return: upper bound of array ' e.g.: Call TestStr(aStrData()) passed array ByRef ' or: Call TestStr(ByVal hStrPtr) passed address of array descriptor ' for array ByVal Local lUB As Long lUB = UBound(aData) ReDim Preserve aData(lUB + 2) aData(lUB + 1) = "apple" aData(lUB + 2) = "orange" Function = UBound(aData) End Function Function PbMain() Local aStrData() As String Local hStrPtr As String Ptr ReDim aStrData(4) Array Assign aStrData() = "cat", "dog", "rat", "bat", "eel" ? "1. Upper bound of string array is: " + Str$(UBound(aStrData)) + $crlf + _ "with value: " + aStrData(UBound(aStrData)) + $crlf + _ "elements: " + Str$(ArrayAttr(aStrData(), 4)) hStrPtr = VarPtr(aStrData()) Call TestStr(ByVal hStrPtr) ' same as: Call TestStr(aStrData()) ? "2. Upper bound of string array is: " + Str$(UBound(aStrData)) + $crlf + _ "with value: " + aStrData(UBound(aStrData)) + $crlf + _ "elements: " + Str$(ArrayAttr(aStrData(), 4)) End Function
A Technique For Using Dynamic Arrays In UDTs
storing dynamic arrays inside a UDT
Tags: array, array descriptor
Join Date: Aug 1998
6 Jul 2009, 09:31 AM
FUNCTION RedimMyArray (Z() AS anthing, newubound AS LONG) AS LONG REDIM Z(newUbound) END FUNCTION
.... is redimming an array via a pointer to its descriptor, too.
It basically HAS to work. It's also the basis for....
Single Function to process any array type (CC3/Win7+) 12-17-03
There's only one way it WON'T work, and that should not occur unless you are using a mixture of PB/DLL 5/6x with PB/Win 7+ AND you are passing a UDT array.
Port Washington WI USA
Copyright © 1998-2022 PowerBASIC Tools, LLC - All Rights Reserved.
Powered by vBulletin® Version 5.7.0
Copyright © 2022 vBulletin Solutions, Inc. All rights reserved.
All times are GMT-5. This page was generated at 05:21 AM.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.