forget memorized table columns

Prev Next

Function Names

forget memorized table columns

Description

Table columns referenced with fixed column names, e.g. [table:Last Name,1], or simply [Last Name] where context infor are available for partial table specifications, B4P will automatically memorize the matching column number for the name provided in order to accelerate performance significantly when additional references are made, e.g. in loops or procedures processing table rows such aslike table process. The acceleration is achieved by checking the column position for the header name provided only once, memorize the column number and use it afterwards.

Benefits: Very high performance
Drawbacks: If the same table access statement is executed with a different table where the row has changed, then the column will be referenced.

See the code exmaple further below for wanted and unwanted effects.
Implicitly memorizing column numbers can be suppressed with following options:

  • Apply a simple formula doing no modifications, e.g. putting the column header name into parentheses.
    Both examples are valid: [table:(Last Name),1], or simply [''+Last Name]
  • Set the system variable runtime settings[memorize table columns] to false to suppress all memorizations
  • Or call the procedure forget memorized table columns which affects the currently running B4P file (but not other ones like calling or called files).

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

0

Examples

       table initialize ( table 1,
       { { Animal, leg count }, { Bird, 2 }, { Dog, 4 }, { Fly, 6 } } );

       table initialize ( table 2,
       { { Animal, weapon, leg count }, { Snake, poison, 0 }, { Tiger, teeth, 4 }, { Lobster, claws, 8 } } );

       define procedure ( legs, { { table name, string } } )
       {
               table process( table name[], echo( [Animal],": ", [leg count], " and ", [(leg count)] ) );
               echo;                                                    // Note the parentheses around (leg count)
       }

       legs( table 1 );

       echo("Hmmmm - Something is strange here ...");
       legs( table 2 ); // Note the mistake outputting the first 'leg count' value.

       echo("Forget memorized table columns: ");
       forget memorized table columns;
       legs( table 2 ); // This one is OK

       echo("If you set runtime settings[memorize table columns] to false, output will always be OK");
       runtime settings[memorize table columns] = false;

       legs( table 1 );
       legs( table 2 ); // All output will be right.  But looking up continuously may slow performance a bit.

Output

Bird: 2 and 2
Dog: 4 and 4
Fly: 6 and 6

Hmmmm - Something is strange here ...
Snake: poison and 0
Tiger: teeth and 4
Lobster: claws and 8

Forget memorized table columns:
Snake: 0 and 0
Tiger: 4 and 4
Lobster: 8 and 8

If you set runtime settings[memorize table columns] to false, output will always be OK
Bird: 2 and 2
Dog: 4 and 4
Fly: 6 and 6

Snake: 0 and 0
Tiger: 4 and 4
Lobster: 8 and 8

Try it yourself: Open LIB_Function_forget_memorized_table_columns.b4p in B4P_Examples.zip. Decompress before use.

See also

memorized table columns