dbTalk Databases Forums  

Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC

comp.databases.pick comp.databases.pick


Discuss Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
frosty
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 06-30-2006 , 03:34 PM






SteveB wrote:
Quote:
Hi all,

Having used other languages heavily in conjunction with mvbasic for
six years now, I often feel serious limitations inherent in pick
basic.

While I am running a process I want to build up a variable *unknown*
number of two dimensional STATIC arrays. I need the arrays to be
STATIC for performance because they are quite large (often about
1000x50) and the process is furiously building them up from scratch.

mvbasic only allows you to acquire memory for storage at the point of
dimensioning static arrays or by building strings. Object orientated
programs are quite happy for you to create a kind of floating array
that can be stored within.

A lot of people think OO is a design process. Well its much more than
that. In this case its about the freedom for variables to contain
"things", in this case arrays.

Cheers,
Steve
You know that mvbasic dynamic arrays are three dimensional, right?
So, one of them can contain an array of two dimensional arrays.

--
frosty




Reply With Quote
  #2  
Old   
frosty
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 06-30-2006 , 05:15 PM






Quote:
frosty wrote:
You know that mvbasic dynamic arrays are three dimensional, right?

SteveB wrote:
Yup.

So, one of them can contain an array of two dimensional arrays.

True but I cant use dynamic arrays because I need the arrays to be
STATIC
for performance because they are quite large (often about 1000x50) and
the process is furiously building them up from scratch.
By "STATIC" do you mean "Dimensioned?"

--
frosty




Reply With Quote
  #3  
Old   
GVP
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-01-2006 , 02:51 PM



Hi,
I don't know what for need arrays with dimensions 1000x50. For
report?...
In any case, it is not good decision. For each element allocated more
then 8 bytes if it is not string (8+len+x if it is string).
1000X50=400K w/o data
I think that better to use rarefied arrays (If You don't need use each
element of array). This technology saves memory and more effectively
than dynamic arrays.
Always remember that for extraction of element of dynamic array system
doing following operations (not full list and some operations not lite)
:
1 retrieves address of array(string)
2 check type
3 scan bytes for delimiter N and store byte's index1
4 continue scan bytes for delimiter N+1 and store byte's index2
5 Allocate memory for new string with Len index2-index1+x
6 Copy bytes from index1 till index2 into new string
7 Performs operation
8 Free allocated memory

For dim array (all operations very lite)
1 retrieves address of array
2 Check type and dimensions
3 Calculate address of array item (ArrayAddr+(Index1*Dim2+index2)*8
4 Check value
5 Performs operation

In addition, main thing is update value of dynamic array item
1 retrieves address of array(string)
2 check type (or convert num to sting with allocation and ......)
3 scan bytes of new element to end of string and store it in NewItemLen

4 scan bytes for delimiter N and store byte's index1
5 continue scan bytes for delimiter N+1 and store byte's index2
6 continue scan bytes for end of string store byte's index3
7 Allocate memory for new array string with Len =
index2+newItemLen+index3-index2
8 Copy bytes from old to new till index1
9 Copy bytes of new item to new array
10 Copy bytes from old to new from index2 till index3
11 Free allocated memory of old array (and temporary string if
converted)
12 Update array pointer

Regards,
Grigory


Reply With Quote
  #4  
Old   
frosty
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-01-2006 , 04:37 PM



Quote:
GVP wrote:
Hi,
I don't know what for need arrays with dimensions 1000x50. For
report?...
SteveB wrote:
Quote:
Yes its a large paged tabulation. I explained it earlier on in the
thread. Actually the 1000x50 is only one report of many that is going
to be built up.

GVP wrote:
I think that better to use rarefied arrays (If You don't need use
each element of array). This technology saves memory and more
effectively than dynamic arrays.
SteveB wrote:
Quote:
Where can I get rarefied arrays in mvbasic?
I've always known them as "sparse" arrays, and implement them
with temporary or "work" files. (Thank you, Mark Brown.)

----------------------------------------------------------------
ArrayCnt = 50000
DIM MyDimArray(ArrayCnt)
MAT MyDimArray=''
*
** Build both arrays
CRT "Dimensioned Load Start-: " : TIMEDATE()
FOR X = 1 TO ArrayCnt
MyDimArray(RND(X)+1) = "DimDimDim"
NEXT X
CRT "Dimensioned Load Stop--: " : TIMEDATE()
*
CRT "Workfile Load Start-----: " : TIMEDATE()
EXECUTE 'CREATE.FILE STEVEB_TEMP 1 1 DYNAMIC' CAPTURING JUNK
OPEN 'STEVEB_TEMP' TO TEMP.FV ELSE STOP
FOR X = 1 TO ArrayCnt
WRITE "DynDynDyn" ON TEMP.FV,RND(X)+1
NEXT X
CRT "Workfile Load Stop------: " : TIMEDATE()
*
** Read both arrays
CRT "Dimensioned Read Start-: " : TIMEDATE()
FOR X = 1 TO ArrayCnt
dummy = MyDimArray(RND(X)+1)
NEXT X
CRT "Dimensioned Read Stop--: " : TIMEDATE()
*
CRT "Workfile Read Start-----: " : TIMEDATE()
SELECT TEMP.FV
LOOP
READNEXT ID ELSE EXIT
READ DUMMY FROM TEMP.FV,ID ELSE CONTINUE
REPEAT
CRT "Workfile Read Stop------: " : TIMEDATE()
----------------------------------------------------------------

Dimensioned Load Start-: 14:31:07 JUL 01 2006
Dimensioned Load Stop--: 14:31:07 JUL 01 2006
Workfile Load Start-----: 14:31:07 JUL 01 2006
Workfile Load Stop------: 14:31:08 JUL 01 2006
Dimensioned Read Start-: 14:31:08 JUL 01 2006
Dimensioned Read Stop--: 14:31:08 JUL 01 2006
Workfile Read Start-----: 14:31:08 JUL 01 2006
Workfile Read Stop------: 14:31:08 JUL 01 2006

Tried bumping ArrayCnt from 50000 to 500000 to get useful
timings, but that crashes uniData(!) -- at least for the
DIMensioned side; the workfile side will continue to
function just fine, thank you.

--
frosty




Reply With Quote
  #5  
Old   
Ross Ferris
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-01-2006 , 07:09 PM



Depends on the environment you are in. D3 and UV both allow you to
re-dimension arrays on the fly (NB: do NOT put them in common unless
they are in their own labelled cmmon block, and even then ...)

I'm sure that CacheMV guys can probably go much better (and deeper)


SteveB wrote:
Quote:
Hi all,

Having used other languages heavily in conjunction with mvbasic for six
years now, I often feel serious limitations inherent in pick basic.

While I am running a process I want to build up a variable *unknown*
number of two dimensional STATIC arrays. I need the arrays to be STATIC
for performance because they are quite large (often about 1000x50) and
the process is furiously building them up from scratch.

mvbasic only allows you to acquire memory for storage at the point of
dimensioning static arrays or by building strings. Object orientated
programs are quite happy for you to create a kind of floating array
that can be stored within.

A lot of people think OO is a design process. Well its much more than
that. In this case its about the freedom for variables to contain
"things", in this case arrays.

Cheers,
Steve


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

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-01-2006 , 07:27 PM



John:

Isn't it great how the dbms can be brought into the mix, instead of
attempting to manipulate memory?

Bill
"frosty" <frostyj (AT) bogus (DOT) tld> wrote

Quote:
GVP wrote:
Hi,
I don't know what for need arrays with dimensions 1000x50. For
report?...

SteveB wrote:
Yes its a large paged tabulation. I explained it earlier on in the
thread. Actually the 1000x50 is only one report of many that is going
to be built up.

GVP wrote:
I think that better to use rarefied arrays (If You don't need use
each element of array). This technology saves memory and more
effectively than dynamic arrays.

SteveB wrote:
Where can I get rarefied arrays in mvbasic?

I've always known them as "sparse" arrays, and implement them
with temporary or "work" files. (Thank you, Mark Brown.)

----------------------------------------------------------------
ArrayCnt = 50000
DIM MyDimArray(ArrayCnt)
MAT MyDimArray=''
*
** Build both arrays
CRT "Dimensioned Load Start-: " : TIMEDATE()
FOR X = 1 TO ArrayCnt
MyDimArray(RND(X)+1) = "DimDimDim"
NEXT X
CRT "Dimensioned Load Stop--: " : TIMEDATE()
*
CRT "Workfile Load Start-----: " : TIMEDATE()
EXECUTE 'CREATE.FILE STEVEB_TEMP 1 1 DYNAMIC' CAPTURING JUNK
OPEN 'STEVEB_TEMP' TO TEMP.FV ELSE STOP
FOR X = 1 TO ArrayCnt
WRITE "DynDynDyn" ON TEMP.FV,RND(X)+1
NEXT X
CRT "Workfile Load Stop------: " : TIMEDATE()
*
** Read both arrays
CRT "Dimensioned Read Start-: " : TIMEDATE()
FOR X = 1 TO ArrayCnt
dummy = MyDimArray(RND(X)+1)
NEXT X
CRT "Dimensioned Read Stop--: " : TIMEDATE()
*
CRT "Workfile Read Start-----: " : TIMEDATE()
SELECT TEMP.FV
LOOP
READNEXT ID ELSE EXIT
READ DUMMY FROM TEMP.FV,ID ELSE CONTINUE
REPEAT
CRT "Workfile Read Stop------: " : TIMEDATE()
----------------------------------------------------------------

Dimensioned Load Start-: 14:31:07 JUL 01 2006
Dimensioned Load Stop--: 14:31:07 JUL 01 2006
Workfile Load Start-----: 14:31:07 JUL 01 2006
Workfile Load Stop------: 14:31:08 JUL 01 2006
Dimensioned Read Start-: 14:31:08 JUL 01 2006
Dimensioned Read Stop--: 14:31:08 JUL 01 2006
Workfile Read Start-----: 14:31:08 JUL 01 2006
Workfile Read Stop------: 14:31:08 JUL 01 2006

Tried bumping ArrayCnt from 50000 to 500000 to get useful
timings, but that crashes uniData(!) -- at least for the
DIMensioned side; the workfile side will continue to
function just fine, thank you.

--
frosty





Reply With Quote
  #7  
Old   
Ross Ferris
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-01-2006 , 10:43 PM



Not necessarily that "amazing" as the "variables" will be held in
RAM/Virtual - the overhead of the "read" (from RAM) isn't that bad
compared to looking up a LARGE variable table - and assuming the file
is well-sized, one hash & you are done.

You could "hide" this whole structure in a single utility routine to
create/destroy/update matrix elements etc, so that the "clumsy code" is
hidden in a "black box" abstraction layer.

By keeping a consistent API, you can then optimise any portion of your
"object API" to take advantage of features on a particular platform,
whilst still keeping the higher level (business logic?) routines
unchanged.

(This is the way that our "snippet technology" works - you can produce
[hand] optimised code for a target database/version/OS from a single
source tree, but getting a tad OT)


SteveB wrote:
Quote:
Frosty wrote:
...

SteveB wrote:

Anyway, I cant duplicate (on QM) your 50,000 dynamic file writes taking
less than a second.

OK I duplicated your results on Unidata (and Jbase 3 but with presized
files). The bad openqm result may be due to it being my own port to
cygwin which is a layer on windows.

The "using files as memory" is very clumsy in code but looks like it
might work performance-wise. Amazing.

Thanks,
Steve


Reply With Quote
  #8  
Old   
GVP
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-02-2006 , 01:03 AM



I think that all in Pick are files. Pick not have RAM. Phisicaly RAM
using only for cash.
In any case (file or array) Pick allocate from overflow.All works very
fast if You write item to file once and then only read it.

Try to analize this algorithm of rarified array:

* Array index is any text (not just number from 1to 50000) for example
NN1xNN2 where NN any number.
* If You don't use item , then item not exist.
* You should determine max number (not index) of items in array

1 Create and open temp file TmpFile
2 Dim RarefiedArr(nMaxRealItems)
3 nItems=0

retrive array index example:

ArrIndexT = "MyIndexExample":NN
READ ArrIndexN FROM TmpFile,ArrIndexT ELSE
nItems+=nItems
* need check on <=nMaxRealItems
ArrIndexN=nItems
WRITE ArrIndexN ON TmpFile,ArrIndexT
END

*All works fast because You read from file only index (few bytes)
*Array index is ArrIndexN
RarefiedArr(ArrIndexN) is Item

It is not the best variant of rarefied array because Pick have not
pointers as in C++. I have template on C++ if need.

Regards,
Grigory


Reply With Quote
  #9  
Old   
Mike Preece
 
Posts: n/a

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-02-2006 , 02:48 AM




frosty wrote:
Quote:
GVP wrote:
Hi,
I don't know what for need arrays with dimensions 1000x50. For
report?...

SteveB wrote:
Yes its a large paged tabulation. I explained it earlier on in the
thread. Actually the 1000x50 is only one report of many that is going
to be built up.

GVP wrote:
I think that better to use rarefied arrays (If You don't need use
each element of array). This technology saves memory and more
effectively than dynamic arrays.

SteveB wrote:
Where can I get rarefied arrays in mvbasic?

I've always known them as "sparse" arrays, and implement them
with temporary or "work" files. (Thank you, Mark Brown.)

----------------------------------------------------------------
ArrayCnt = 50000
DIM MyDimArray(ArrayCnt)
MAT MyDimArray=''
*
** Build both arrays
CRT "Dimensioned Load Start-: " : TIMEDATE()
FOR X = 1 TO ArrayCnt
MyDimArray(RND(X)+1) = "DimDimDim"
NEXT X
CRT "Dimensioned Load Stop--: " : TIMEDATE()
*
CRT "Workfile Load Start-----: " : TIMEDATE()
EXECUTE 'CREATE.FILE STEVEB_TEMP 1 1 DYNAMIC' CAPTURING JUNK
OPEN 'STEVEB_TEMP' TO TEMP.FV ELSE STOP
FOR X = 1 TO ArrayCnt
WRITE "DynDynDyn" ON TEMP.FV,RND(X)+1
Very strong possibility of overwriting at least some records - and
therefore reading fewer than 50,000 records later. Maybe not the clean
potato. Also - if the requirement is for two (or more) dimensional
arrays we might want to use READU...LOCATE...INS to create an attribute
list (maybe with multivalues and maybe subvalues). This satisfies the
requirement if the dimensions are totally variable. You could possibly
go further and use MATREADU/MATWRITE... MATREAD. I still want to know
more about the actual requirements though. As a side issue - would it
be any more/less efficient to OPEN the workfile as the default -
without a file variable?

Quote:
NEXT X
CRT "Workfile Load Stop------: " : TIMEDATE()
*
** Read both arrays
CRT "Dimensioned Read Start-: " : TIMEDATE()
FOR X = 1 TO ArrayCnt
dummy = MyDimArray(RND(X)+1)
NEXT X
CRT "Dimensioned Read Stop--: " : TIMEDATE()
*
CRT "Workfile Read Start-----: " : TIMEDATE()
SELECT TEMP.FV
LOOP
READNEXT ID ELSE EXIT
READ DUMMY FROM TEMP.FV,ID ELSE CONTINUE
REPEAT
CRT "Workfile Read Stop------: " : TIMEDATE()
----------------------------------------------------------------

Dimensioned Load Start-: 14:31:07 JUL 01 2006
Dimensioned Load Stop--: 14:31:07 JUL 01 2006
Workfile Load Start-----: 14:31:07 JUL 01 2006
Workfile Load Stop------: 14:31:08 JUL 01 2006
Dimensioned Read Start-: 14:31:08 JUL 01 2006
Dimensioned Read Stop--: 14:31:08 JUL 01 2006
Workfile Read Start-----: 14:31:08 JUL 01 2006
Workfile Read Stop------: 14:31:08 JUL 01 2006

Tried bumping ArrayCnt from 50000 to 500000 to get useful
timings, but that crashes uniData(!) -- at least for the
DIMensioned side; the workfile side will continue to
function just fine, thank you.

--
frosty


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

Default Re: Arrays of Arrays is useful, a hallmark of OO, and missing in MVBASIC - 07-02-2006 , 02:58 AM



Hi Ross
Please never even dream of suggesting re-dimension on the fly. Somebody at
Pick systems destroyed the transfer from Dos to Pick when this was first
implemented. What was really sad was that particular program was one of the
best implemented and best documented programs from Pick until that amateur
got at it.
As a thought surely your Visage reporting tool would do everything this guy
is talking about without re-inventing the wheel.
Peter McMurray



"Ross Ferris" <rossf (AT) stamina (DOT) com.au> wrote

Quote:
Depends on the environment you are in. D3 and UV both allow you to
re-dimension arrays on the fly (NB: do NOT put them in common unless
they are in their own labelled cmmon block, and even then ...)

I'm sure that CacheMV guys can probably go much better (and deeper)


SteveB wrote:
Hi all,

Having used other languages heavily in conjunction with mvbasic for six
years now, I often feel serious limitations inherent in pick basic.

While I am running a process I want to build up a variable *unknown*
number of two dimensional STATIC arrays. I need the arrays to be STATIC
for performance because they are quite large (often about 1000x50) and
the process is furiously building them up from scratch.

mvbasic only allows you to acquire memory for storage at the point of
dimensioning static arrays or by building strings. Object orientated
programs are quite happy for you to create a kind of floating array
that can be stored within.

A lot of people think OO is a design process. Well its much more than
that. In this case its about the freedom for variables to contain
"things", in this case arrays.

Cheers,
Steve




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.