NetTalk Central

Author Topic: Providing for 'Global' variables  (Read 5901 times)

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Providing for 'Global' variables
« on: February 02, 2014, 11:34:55 AM »
Hi

I have heard Bruce talk about this a bit but before embarking on a new round of development I just wanted to make sure that I had the facts straight:

  • For a Windows program (one copy per user) Global variables allow data created in one procedure to be used by other procedures
  • For a NetTalk program (one copy many users) this is not viable
  • To provide 'Global' variables with NT we have to either create Session variables or file-based variables
  • The fastest way to provide file-based variables is to utilise Clarion's In Memory Driver
  • Data in the file is segregated between users via the Session Id

I have a procedure in which I define and populate an array viz:

Accln               GROUP,PRE(AC),DIM(200)           
time                 DECIMAL(7,2)                         
gearinst           REAL                                 
gearsmoo        REAL                                 
engrpm            REAL                                 
etc . . .

I want to access this array in other procedures and intend to create an In Memory table that has one row per table index (200 rows) each prefixed with the Session Id.

This should allow me to keep the user data separate and I will delete the Session records from the table as soon as logically possible and at Session end.

Does this sound the right way to go?

Thanks

Keith
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

Nick

  • Full Member
  • ***
  • Posts: 118
    • View Profile
    • Email
Re: Providing for 'Global' variables
« Reply #1 on: February 02, 2014, 01:42:34 PM »
I've used the InMemory file for the same purpose and that works fine.

Nick

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Providing for 'Global' variables
« Reply #2 on: February 02, 2014, 03:23:09 PM »
The other option is using XML files to store your data. XFiles does a good job of reading\writing this data between groups, Q's and files.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11312
    • View Profile
Re: Providing for 'Global' variables
« Reply #3 on: February 02, 2014, 08:34:04 PM »
In memory is great for this. Just be sure to add clean-up code to the NotifyDeleteSession method in web handler to delete records when a session ends.

Cheers
Bruce

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Providing for 'Global' variables
« Reply #4 on: February 05, 2014, 01:31:02 PM »
Thanks Bruce.

There is another aspect of this 'Global variables via an In Memory Table' approach that I need some advice on.

It relates to the size of the variable pool and the expected number of concurrent sessions.  For a small pool where one row in a table will hold all of the data this is obviously not going to be an issue but in my case I have replicated a Group (with 17 fields) that has a Dimension of 2000 as a Table - so 34,000 fields per session.  Most of these fields are of type 'Real' and I'm not sure how many bytes are allocated but say 8 which means about 276KB per session.  Now how many concurrent sessions - hopefully lots but indeterminate.

So for this reason I decided that it would not be safe to just delete the session records in the NotifyDeleteSession method since that would mean that all 2000 rows would be around for all active sessions.  Because within a session a user can perform many actions that cause the values of all of these variable to change I actually delete all of the session rows before recalculating the values (and the rows) so I only get one set of 2000 rows per session.

The other complication is that the reason for doing all of this is that I currently have three Graph procedures which load data from my Table (hence the need for 'global' variables)..  So I want to delete the session rows for a single request after all of the procedures have completed.

After getting a request to 'recalculate', in ProcedureA  I delete the current session rows and recreate (writing a new 2000 rows).  ProcedureA also calls for the three Graphs to be reset and I have three procedures executing out of three separate windows.  In each of these the Graph data is loaded from the Table.

First question is: if in the Reset list on the Client Side tab the three graphs are (in order) - Graph1, Graph2, Graph3 then could I assume that all of the processing is complete at the end of the loading of the data for Graph3 and could I delete the session rows then?

Second question is: because the above solution feels a bit clunky and depends on the order of the Reset list which is not obvious and may change would it be better to control this by setting a local variable loc:numberofgraphs to 3, decrementing in the load code for each graph and deleting the session rows when it gets to 0?

Third question is: Is it possible to generate three graphs in one procedure?

Thanks

Keith
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Providing for 'Global' variables
« Reply #5 on: February 05, 2014, 03:41:46 PM »
Hi Keith,

where are you loading data from into your memory table? why do you need to delete this from the memory table after the graph's run? what else do you use this memory table data for? There may be a better way...

Kev

Keith

  • Sr. Member
  • ****
  • Posts: 306
    • View Profile
    • Email
Re: Providing for 'Global' variables
« Reply #6 on: February 05, 2014, 05:08:37 PM »
Kevin

My app calculates drag strip metrics at a granularity of 1/100th sec for 20 sec = 2000 sets of values.  The user can change the starting variables (70 odd) and 'Calculate' which reworks all the numbers.  I delete the previous rows (or values ) in the table before re-populating with the new ones.  I use 1/10th of these values to draw three graphs - Acceleration, Distance and Speed all versus time and the data comes from the table.

The graph is on a Window and the data is loaded in the Init embed.

I think that I need to delete the rows after the graphs have been produced (i.e after all of the processing for that request within the session) because a session can last a long time and if I had 00s (000s!) of sessions then I could run out of Ram.

In other words, I understand that you would normally delete the session rows at session end but I have a lot of data which is a difference and I wanted to know what best practice would be.

Cheers

Keith
Clarion 10.0.0 build 12799
NetTalk 9.31
StringTheory 2.65
InsightGraphing 2.27

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Providing for 'Global' variables
« Reply #7 on: February 05, 2014, 06:49:55 PM »
ok that makes sense. so they need to be "global" in the sense that IG can use the data.

here are some long shots...

- pass your 70 odd variables as a group to the graph procedures, do the calc and create a Q with desired values inside the procedure to use with IG. Depends how long it takes to do your calc x 3
- pass the 2000 (or can you just pass 1/10th 200) values to IG procedure as a group and then load that into a Q for IG to process?
- can you create an object and pass the object like String Theory?

You could even run your graph procedures on worker threads, you just need a mechanism to know when to reset your webpage controls.