coding 'Output 
Author Message
 coding 'Output

What's the best way to do something like X'Output when type X only has
part of the story?  Say "type X is array ..."  but X is an array of
sampled signal and there's an associated sampling rate etc.  Making
type X(Rate : Positive; Length : Positive) is record
  Data : Data_Array(1 .. Length);
would require slice assignments to/from Data and Data is typically large,
so that's not a good solution.


Fri, 30 Dec 2005 14:34:59 GMT  
 coding 'Output

Quote:

> What's the best way to do something like X'Output when
> type X only has part of the story?  Say "type X is array ..."
> but X is an array of sampled signal and there's an
> associated sampling rate etc.  Making
>    type X (Rate : Positive; Length : Positive) is
>       record
>          Data : Data_Array(1 .. Length);
> would require slice assignments to/from Data and Data is
> typically large, so that's not a good solution.

Why is this (putting the array and other info into a record type) not a good
solution? What have large slices got to do with it?

--
Nick Roberts



Sat, 31 Dec 2005 06:45:17 GMT  
 coding 'Output
Quote:
>> would require slice assignments to/from Data and Data is
>> typically large, so that's not a good solution.
>Why is this (putting the array and other info into a record type) not a good
>solution? What have large slices got to do with it?

  Because it's often necessary to pass large slices and time is important.
eg, given
 Data : X(1 .. 50_000);
I can call
 Process_Middle(Rate, X(15_000 .. 35_000));
passing nothing just a pointer and bounds.  But if Rate and Data are part
of a record, I'd have to pass
 Process_Middle(X_Record'(Rate, X(15_000 .. 35_000)));
which I believe would require building a temporary object and copying
20K elements of X.


Sat, 31 Dec 2005 07:01:13 GMT  
 coding 'Output

Quote:
> > > would require slice assignments to/from Data
> > > and Data is typically large, so that's not a good
> > > solution.
> > Why is this (putting the array and other info into
> > a record type) not a good solution? What have
> > large slices got to do with it?
> Because it's often necessary to pass large slices
> and time is important. eg, given
>   Data : X(1 .. 50_000);
> I can call
>   Process_Middle(Rate, X(15_000 .. 35_000));
> passing nothing just a pointer and bounds.  But if
> Rate and Data are part of a record, I'd have to
> pass
>   Process_Middle(X_Record'(Rate, X(15_000 .. 35_000)));
> which I believe would require building a temporary object
> and copying 20K elements of X.

Well I see your point now, but by golly there are many possible solutions!

----------
Solution 1

Declare the relevant procedures so that they take the array and other
information as separate parameters. E.g.:

   procedure Process_Middle (Rate: in ...; Data: in Data_Array);

This does not prevent the array and other information being otherwise kept
in a record. A call using the data in a record named Trial_1, say, might
look like:

  Process_Middle( Trial_1.Rate, Trial_1.Data(15_000..35_000) );

----------
Solution 2

Keep a pointer to the array in a record which contains the other (small)
information. E.g.:

   type Data_Ref is access all Data_Array;

   type Sample_Descriptor is
      record
         Data: Data_Ref;
         Rate: ...;
      end record;

   procedure Process_Middle (Sample: in Sample_Descriptor);

A call to this procedure might then look like:

   Process_Middle( (Trial_1.Rate, Trial_1.Data(15_000..35_000)'Access) );

Note that in this case the constructed temporary record is small. The array
referenced by Trial_1.Data must be aliased (in many cases it will be
preferable to create it by an allocator).

----------
Solution 3

Pass the slice bounds into the relevant procedures. E.g.:

   subtype Sample_Index is Natural;

   type Data_Array is array (Sample_Index range <>) of Sample_Value;

   type Sample_Set (Last: Sample_Index) is
      record
         Data: Data_Array(0..Last);
         Rate: ...;
      end record;

   procedure Process_Middle (Data: in Sample_Set; First, Last: in
Sample_Index);

A call to this procedure might look like:

   Process_Middle(Trial_1,15_000,35_000);

----------
I'm sure there are many other possible approaches, probably some more
elegant than these. What you really require will depend on your particular
application, and your own preferences. If you are still stumped, and are
prepared to give more a detailed outline of your problem, I'd be happy to
make more precise suggestions.

Best of luck.

--
Nick Roberts



Sun, 01 Jan 2006 05:23:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 'split' creates extra output

2. Outputting 'Raw' printer data

3. Undetermined Output in 'X' state

4. Redefining 'Class'Output

5. capture 'system' output

6. Grab output from 'tail'

7. Legacy Code 2, The Code's Revenge!

8. Expect question: using patterns and 'send' in a -input/-output -input/-output loop

9. CW2.0 App gen code output

10. compiling code but no output to screen

11. Can Labview output source code in text format?

12. Verilog code for Inverted, Open collector, Output Enable Bus

 

 
Powered by phpBB® Forum Software