[futurebasic] Re: [FB] re: XREF vs Growing your own

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1998 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Fri, 27 Nov 98 11:06:34 -0600
>However, I often have to work with numerical data structured in tables of
>varying dimensions, not known at compile time. For example, my user may
>acquire data sent on 1 to 8 (but perhaps 15 in the future) channels during
>varying time at a given sampling rate (Numbers are laying contiguously in a
>handle, the next sampling after the last USED channel). My application is
>has to be able to access each of these values. The use of XREFerencing
>whould imply that data should be displayed in an structure created
>differently whether the number of channel is something like:
>
>select chanNb
>	case 1
>		XREF@ myXArray&(40000)
>	case 2
>		XREF@ myXArray&(40000,1)
>	case 3
>		XREF@ myXArray&(40000,2)
>..........................
>end select
>
>It doesn't seem very handy and the syntax is not homogenous.(what about
>XREF@ myXArray&(40000,0) ). For the moment I prefer keep my own grown
>structure.
>
Guy,

I don't see any reason to change something that is working well. However, 
another approach to your particular scenario would be to put your data 
handle into a single-dimensional array, lock the handle, and use VARPTR 
to get a pointer to the particular data-set you want to address. It might 
look something like this:
  DIM myXArray&
		XREF@ myXArray&(40000)
  DIM myXDataSet&
  XREF myXDataSet&(15)

  myXArray& = myDataHandle&
  err = FN HLOCK(myXArray&)
  myXDataSet& = @myXArray&(set2Get * chanNb) 'address of channel 0
  channelValue& = myXDataSet&(whichChannel)
  err = FNHUNLOCK(myXArray&)

It's likely that your solution is as easy or even simpler than this, but 
I offer it as another example of the utility of the XREF statements. I 
would probably dispense with the myXDataSet& array and just add the 
channel to the first calculation:
  channelValue& = myXArray&(set2Get * chanNb + whichChannel)
  'no need to lock for this one
but reading the code, the first might seem a little clearer.

>The only QuickBasic feature I don't find in FB (and I regret) is the true
>dynamical allocation of memory
>
>DIM A&(n%,m%,p%)
>
Ooh, wouldn't that be neat! I think XREF is about as close as we can get.

 0"0
 =J= a  y
  "