[futurebasic] Re: [FB][FB^3] Consecutive variables

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2000 : Group Archive : Group : All Groups

From: Robin <robinc@...>
Date: Thu, 03 Feb 2000 09:43:13 +1000
Further re:

===========================================
>> My question is: in FB^3, can you *rely on* consecutively DIM @'d variables
>> being consecutive in memory, so that with for example:
>> 
>> DEFINT a-z
>> DIM @ var1,var2&,var3,var4
>> 
>> @var4 is 2 after @var3 which is 4 after @var2& which is 2 after @var1?
> 
> Variables won't necessarily be consecutive if you use the compiler
> prefernces option "Align variables to proper boundaries". In the following,
> you get different results depending on the preference setting.
> 
> 
> '-----------------------------
> DIM @ var1, var2&, var3, var4
> 
> print ""  @var2&-@var1, @var3-@var2&, @var4-@var3
> //  4  4  2  with Align variables to proper boundaries ON
> //  2  4  2  with Align variables to proper boundaries OFF
> '-----------------------------
> 
> Robert P.
===========================================

Thanks for that helpful answer. It is starting to look tricky. Does this
also apply to "proper" records? For example, what if you do this with "Align
variables to proper boundaries" on:

DEFINT a-z
BEGIN RECORD somerecord
    DIM field1
    DIM field2&
    DIM field3
END RECORD

And we have a function like so:

LOCAL
DIM rec1 AS somerecord
DIM rec2 AS somerecord
LOCAL FN Called
    ' set rec1 fields...
    rec2 = rec1
    ' do something...
END FN

Say the stack when we call FN Called is on a 4-byte boundary. Will it then
force field2& to be also on a 4-byte boundary in both cases so what we end
up with in memory is:

--- 4-byte boundary ---
  rec1.field1 (2 bytes)
  padding     (2 bytes)
--- 4-byte boundary ---
  rec1.field2 (4 bytes)
--- 4-byte boundary ---
  rec1.field3 (2 bytes)
  rec2.field1 (2 bytes)
--- 4-byte boundary ---
  rec2.field2 (4 bytes)
--- 4-byte boundary ---
  rec2.field3 (2 bytes)

So that rec2 = rec1 will actually be trying to assign unequal blocks of
memory? Or are the starts of records always aligned to long word boundaries
or to boundaries of their own length? If to long word boundaries, what
happens in the analogous case to the above where we have double-precision fp
fields?

Also, are pseudo-records aligned similarly to true records, or are they
treated as if they are a run of simple variables?

I think I might leave that option off for the moment and use DIM && etc if I
want fp speed!

-- 
Robin
====================================================
Genesearch Pty Ltd
E-mail: robinc@...
WWW:    http://www.genesearch.com.au
====================================================