Using 2D arrays in extension command DLLs

Questions and coding techniques, including USB cameras and devices.
Post Reply
Posts: 10
Joined: Mon Jul 13, 2015 2:31 pm

Using 2D arrays in extension command DLLs

Post by StewD » Sat Oct 05, 2019 10:10 am

When creating a set of extension commands in a DLL, it's unclear how 2D arrays are defined and used. The command arg list data types (i.e. the command syntax) are declared in the DLL RegisterExtLibCmdSet(...) function. Suppose we define a command set with functions starting with "abc...". A simple command sequence is

Array2(SensorIDValues[20,20], ElementCount) // declare the array

to store the identifier and sensor state in an integer array. A simple extension command might be

The extension command arg list definition would be:
lpCmd[nCommands++] = (LPSTR)"\",\"abcGetSensorData\", Res, P_VARIANT_ARRAY,

In the arg pointer list, these are
anArgBuffer[0] == SensorIDValues array pointer
anArgBuffer[1,2] == array start row and column indices
anArgBuffer[3] == return variable (Result)

For efficiency and code simplicity, 2D arrays are stored internally as one contiguous memory region, with the [row,column] indices used to set the pointer to the entry location. By comparison, if the addressing mode [row][column] had been used, there would have been two memory regions (almost certainly discontiguous) to be managed, adding to code complexity.

If you have more questions on arrays, please comment or contact Tech Support.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest