I need to have local arrays in my Cicode functions, but Cicode
only allows module and global arrays. What are the
alternatives?

Or…

How can I return multiple values from a function?

Solution:

Citect Queues can be used to solve these data storage problems.
Queues can be dynamically created and destroyed. They are
referenced by a handle so they can be passed to other functions,
and other instances of the same function can have different data.
By setting the citect.ini parameter [Code]Queue=-1 they have
unlimited length. The drawback is that the more elements they
contain, the slower they become.

Table Functions' Usage

The attached Cicode file contains a set of functions that use
Citect queues to hold tables of data. To use them, you need to
create the table (TableCreate() function), add items to it
(TableSet), read them back (TableGet), and finally destroy the
table (TableClose) when it's no longer needed. For example:

These functions could be used with the sorting algorithms in
Q3750. However, using multiple arrays
provides better performance. With 479 strings, queues took about 3x
as long as arrays (tested with the Shell sort algorithm). With
5,000 elements, queues took about 65x as long as arrays. Since
Cicode arrays only hold 128 character strings and queues hold 256
character strings, there may be some cases where arrays would not
be usable so a queue sorting function is included below.

Table Viewing

Another use for these functions is for viewing normal arrays
during debugging. The Cicode Editor does not display the values
stored in arrays, but you can copy all the elements to a queue and
view it in the Citect Kernel. To view the table, go to the Main
window in the Kernel and type PAGE QUEUE <Enter>. Press
<Page Down> until the table name appears. By default, tables
will all be named 'TableQueue'. It will be listed after all the
tables Citect uses internally. Use the arrow keys to scroll through
the values. Note: the element numbers display in hexadecimal and
only the first 32 characters of each string are displayed.

For example, you could add this code fragment to your function
to display the first 100 values that are in an array named
mrProcessEvents:

INT hTable = TableCreate("ProcessEvents");

INT iCount;

FOR iCount =0TO99DO

TableSet(hTable, iCount, mrProcessEvents[iCount], TRUE);

END

After viewing it, make sure to call TableClose(hTable) to
destroy it.

Table Cicode Functions

Add the attached Cicode file to your project to use the
table functions.