Forum Navigation
You need to log in to create posts and topics.

Re: [FUTUREBASIC] Re: PG 5 ? (2)

Posted by: rbrown <rbrown@...>

David Cottrell wrote:
> Can someone tell me the "correct" way to set the size of a handle for use
> with with XREF?
>
> My guess is that if I have 10 elements in my array then if:
>
> TYPE EG SIZE
> string array stuff$ 10*256
> interger array stuff% 10*2
> single precision stuff! 10*(precision set in prefs)
> double precision stuff# 10*(precision set in prefs)

First, be sure you're counting element #0 in your array (assuming you
haven't set the "Arrays without element zero" preference--and _real_
programmers always count from zero :-). So a 10-element stuff$() array
would only go up to stuff$(9). Conversely, if you need it to go up to
stuff$(10), you need to reserve space for 11 elements.

In a string array dimensioned as "XREF n stuff$(..)", each element
occupies (n+1) bytes if n is odd, or (n+2) bytes if n is even. If you
don't specify n, it defaults to 255, which means each element occupies
256 bytes.

In a short integer (%) array, each element occupies 2 bytes.

In a long integer array(&), each element occupies 4 bytes.

In a single (!) array, I _think_ each element occupies ((p/2)+1) bytes,
where p is an (even) number representing the number of digits of
precision. If p is odd, then the element occupies ((p+1)/2 + 1) bytes.

In a double (#) array, I think each element occupies (p/2 + 2) bytes if
p is even, or ((p+1)/2 + 2) bytes if p is odd.

You can easily verify whether I'm right about the (!) and (#) types:
just do this:

DIM testArray!(5)
PRINT VARPTR(testArray!(1)) - VARPTR(testArray!(0))

(Likewise for a "testArray#()" (double) array).

- Rick