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.
And I don't understand why the REDIM AT of 'myarray()' is NOT first ERASEing the "Real Array" of the same name before allowing you to re-define the symbol "myarray()" as an absolute array.
As the F1 help says,
The AT address clause indicates the array is to be an absolute array. Absolute arrays are not reset by the REDIM statement, nor are they reset when the Sub/Function/Method/Property exits, but they can be reset with the RESET statement. See the discussion in the DIM topic for more information on absolute arrays.
Code:
GLOBAL MyArray() AS MyUDT
just sets the scene for dimensioning (by DIM or REDIM) the array to be mapped at the AT address supplied.
I use this lots.
I don't use multi-dimensional arrays though - my brain is just not up to it. Instead, I calculate the subscript to a 1D array, so if there is an array of rows x columns, my index for row n, col m would be n*maxcolumns + m. Rows and columns starting at zero, of course.
If you want an official answer, you'll have to contact support.
But I still don't understand what you are doing: Why 'REDIM myarray() AT' when you have already REDIMed 'myarray()' as a 'real' array, with the compiler managing the underlying memory?
And I don't understand why the REDIM AT of 'myarray()' is NOT first ERASEing the "Real Array" of the same name before allowing you to re-define the symbol "myarray()" as an absolute array.
Would not be surprised if that "support" isn't teminated in some future version of the compiler, especially after I send in a bug report on it after I test it and verify what is happening.
Well I'm an idiot. My pseudo-code I wrote above does work, but I did not write it correctly in my actual code.
Getting back the REDIM. I have always used this method before and I never found it to be a problem, but if there's a better way I would be happy to do it.
Maybe someone from PB staff could answer if REDIM would actually cause any problems or not in a case like this.
I don't like the fact you are redimming the array to which you passed a reference.
Presumably myarray() was a "real" array when you filled it (code not shown), but now you are now trying to redefine it as an absolute (a "DIM AT") array?
You should also be testing the system ERR variable in your sub following the REDIM.
What you doing does not make any sense.... why REDIM a real array you already have as an absolute array? (which, if it is allowed, should not be IMNSHO). (You should know f it's allowed as soon as you check ERR after the REDIM).
FWIW, there's no reason you cannot create multi-dimensional absolute arrays... but you do need to pay attention to the organization of the underlying data in memory.
Alright I have been using the DIM ... AT to create a pointer array to allow a DLL to read and change Array data from my main program.
This works great, except when I tried doing it with a Multidemsional UDT Array (although the UDT probably has nothing to do with it).
Here's an example:
DLL Code:
Code:
GLOBAL MyArray() AS MyUDT
SUB LinkArray ALIAS "LinkArray" (BYREF ArrayPtr AS MyUDT, BYVAL ArrayCnt AS LONG) EXPORT
REDIM MyArray(1 TO 3, 1 TO ArrayCnt) AS MyUDT AT VARPTR(ArrayPtr)
END SUB
Program Code:
Code:
LinkArray MyArray(1,1), 3
For some reason every array element in my DLL is the same as value as MyArray(1,1). I've tried MyArray(0) and MyArray(0,0), which as expected don't work at all. Do I have to pass the Array differently if its multidimensional? Or do I need to handle it in the DLL different?
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.
Leave a comment: