dbTalk Databases Forums  

Trying to matread in a subroutine...

comp.databases.pick comp.databases.pick


Discuss Trying to matread in a subroutine... in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Peter McMurray
 
Posts: n/a

Default Re: Trying to matread in a subroutine... - 10-14-2005 , 04:19 PM






Hi
I have to disagree re speed.

Matrix handling of arrays is orders of magnitude faster than dynamic arrays.
Particularly in the case in point where large amounts of data are to be
handled. Consider the work involved; for those who remember Cobol moves,
the first chunk has to be moved to a new position large enough to hold the
altered record , the change has to be concatenated, then the remaining chunk
has to be concatenated. The further down an item one goes the more time it
takes to find the limit of the first chunk. Therefore changing more than
one element is always going to be slower for a dynamic array. The time lost
on the read is made up everywhere else. Also one should never keep
redimensioning an array as it will crucify the system. The worst example of
this is where some junior got at the Dos to Pick transfer program and
wrecked it back in the 1980's. A further benefit of matrices is that an
element less than 10 bytes long will be altered in situ and an element
longer will be identified by an exact address from the initial 10 byte
position without having to count through the entire record.

However there is a far greater reason to use matrices when handling normal
data. This is the use of the equate. I hate to think of how often I have
seen systems messed up by people using offsets in dynamic arrays because
they were quite certain that it was field 17 or whatever that needed
altering. The best way to access is always to name the field and alter the
named item. Then at least the next programmer will know what you meant to
alter. I have never been lucky enough to fall across a site apart from my
own that kept file definition documentation up to date. I forced the issue
by using a generator that goes to the documentation to produce the program.

Peter McMurray



Reply With Quote
  #12  
Old   
Dale Benedict
 
Posts: n/a

Default Re: Trying to matread in a subroutine... - 10-14-2005 , 04:52 PM







"Peter McMurray" <excalibur21 (AT) bigpond (DOT) com> wrote

Quote:
Hi
I have to disagree re speed.

Matrix handling of arrays is orders of magnitude faster than dynamic
arrays.
Particularly in the case in point where large amounts of data are to be
handled. Consider the work involved; for those who remember Cobol moves,
the first chunk has to be moved to a new position large enough to hold the
altered record , the change has to be concatenated, then the remaining
chunk
has to be concatenated. The further down an item one goes the more time
it
takes to find the limit of the first chunk. Therefore changing more than
one element is always going to be slower for a dynamic array. The time
lost
on the read is made up everywhere else. Also one should never keep
redimensioning an array as it will crucify the system. The worst example
of
this is where some junior got at the Dos to Pick transfer program and
wrecked it back in the 1980's. A further benefit of matrices is that an
element less than 10 bytes long will be altered in situ and an element
longer will be identified by an exact address from the initial 10 byte
position without having to count through the entire record.
Don't compare the old COBOL with Pick for functionality under the hood.
I've done some cursory (sp?) speed checks and with a small amount of code
for reading and writing items the difference in working with 10,000 items
with 50 attributes the difference in speed was less than a second.

Quote:
However there is a far greater reason to use matrices when handling
normal
data. This is the use of the equate. I hate to think of how often I have
seen systems messed up by people using offsets in dynamic arrays because
they were quite certain that it was field 17 or whatever that needed
altering. The best way to access is always to name the field and alter
the
named item. Then at least the next programmer will know what you meant to
alter. I have never been lucky enough to fall across a site apart from my
own that kept file definition documentation up to date. I forced the
issue
by using a generator that goes to the documentation to produce the
program.

You can still use equates with dynamic arrays! And it can make the program
more understandable and can be used with dynamic or dimensioned arrays,
albeit there is more typing to generate the code.

eg.

equ name.attr to 5

read cust.rec from...

print cust.rec<name.attr>
....
or

equ name.attr to 5
dim cust.rec(10)
read cust.rec from...

print cust.rec(name.attr)

Both work and I find this way there is no mixup in where the data is coming
from or going.

Add some programming standards to ensure that attribute definitions and item
names don't get intermixed and you get far easier code to read.

I've run into code which used dimensioned arrays and equating of each
element of the array to a symbol name. Because of no standards the arrays
get passed to subroutines where another programmer used their on different
symbol names.

Let's face facts... poor code can and does get written. Good standards
makes life easier in the long run.


Dale




Reply With Quote
  #13  
Old   
Peter McMurray
 
Posts: n/a

Default Re: Trying to matread in a subroutine... - 10-14-2005 , 06:32 PM



Hi
My reference to speed was particularly concerned with handling large arrays.
I agree a 50 element array could not be timed accurately because of the
latency of the clock function. I still believe it to be more efficient. I
used the cobol method to explain how it happens, and yes this is still the
only way that I have ever found described of building an item. Modern
methods are still the same. In fact if one looks at low level code one will
also find that the much maligned GOTO is a mjor player although I doubt that
many people today will build an instruction on the fly at say spot zero and
then GOTO it for execution. This sort of code was essential when limited to
16K bytes.

However when dealing with large amounts of data as frequently occurs with
transferring flat files from disparate systems the matrix method is vastly
more efficient.

I agree that one can equate to an offset however that requires all the
attendant move/shuffle of the dynamic array, losing the speed advantage of
the exact positioning of the matrix element.
Peter McMurray

"Dale Benedict" <dale_knowspam_benedict (AT) flightcraft (DOT) ca> wrote

Quote:
"Peter McMurray" <excalibur21 (AT) bigpond (DOT) com> wrote in message
news:jhV3f.17893$U51.7552 (AT) news-server (DOT) bigpond.net.au...



Reply With Quote
  #14  
Old   
Bill H
 
Posts: n/a

Default Re: Trying to matread in a subroutine... - 10-15-2005 , 06:05 AM



Tedd:

Maybe I missed something here but this is the D3 documentation:

A "dim" statement without the number of elements specified, such as in the
case: "dim a()", may only be used in a subroutine. FlashBASIC run-time
determines the number of elements after a "matread".

An array must be dimensioned prior to being referenced within a program.
After an array has been dimensioned, it may be redimensioned later within a
program. When the dimensioning parameters are changed, the new array will:

- retain those elements with the same indexes that were in the old array;

- have any new elements initialized to a unassigned state;

- lose any unreferenced elements (those elements in the old array with
indicies not present in the new array).

Bill

"Tedd Scofield" <tedd_scofield (AT) hotmail (DOT) com> wrote

Quote:
I promise I won't come back here to CDP and say 'but I told Raining
Data about this!' =)

Well, the thing I'm trying to do is read reports of varying size
directly into a dimensioned array without any necessary steps. In
otherwords, I was hoping the database could do the dirty work of sizing
up that array for me.

I would also like figure out how to do this in a manner that will work
on other flavors of PICK, not just D3's implementation. But if any
implementaion (not just D3) offers a specific optimization for this
sort of job I'm all for using those too in the name of performance
tuning.

The AP manual lead me to believe I could matread a record without
having to size the dim'd array but for now the only solution I've come
up with is to read it into a dynamic array, dcount the @am's and size
the dimensioned array off of that.




Reply With Quote
  #15  
Old   
Tedd Scofield
 
Posts: n/a

Default Re: Trying to matread in a subroutine... - 10-15-2005 , 12:21 PM



Aye, I read that part too.

Bill H wrote:
Quote:
Tedd:

Maybe I missed something here but this is the D3 documentation:

A "dim" statement without the number of elements specified, such as in the
case: "dim a()", may only be used in a subroutine. FlashBASIC run-time
determines the number of elements after a "matread".
This seems to be the point that the book says I can do that I cannot
get to work. The only way I've seen it work is when a dimensioned
array is sized in the calling program passed in tne subroutine
arguments (or the commons?).

I'd love to see an example of a matread actually sizing the dimensioned
array it uses to read the record into. The D3 "book" certainly alludes
to that being a possiblity. What about other PICK flavors?



Reply With Quote
  #16  
Old   
Bill H
 
Posts: n/a

Default Re: Trying to matread in a subroutine... - 10-15-2005 , 07:28 PM



Tedd:

I couldn't either. I used D3NT Flashed/Unflashed and D3Linux
Flashed/Unflashed. So much for good ideas. :-)

Bill

"Tedd Scofield" <tedd_scofield (AT) hotmail (DOT) com> wrote

Quote:
Aye, I read that part too.

Bill H wrote:
Tedd:

Maybe I missed something here but this is the D3 documentation:

A "dim" statement without the number of elements specified, such as in
the
case: "dim a()", may only be used in a subroutine. FlashBASIC run-time
determines the number of elements after a "matread".

This seems to be the point that the book says I can do that I cannot
get to work. The only way I've seen it work is when a dimensioned
array is sized in the calling program passed in tne subroutine
arguments (or the commons?).

I'd love to see an example of a matread actually sizing the dimensioned
array it uses to read the record into. The D3 "book" certainly alludes
to that being a possiblity. What about other PICK flavors?




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.