The C Data Structure

If even the macro interface is not fast enough for you, you can access the internal data structure for all the basic types except string. You cannot access the internal data structure for arrays of strings, interfaces and objects.

The basic form of the C data structure for type XXXX is:


struct sidl__array_vtable {

  /* Release resources associted with the array (refcount at zero) */
  void (*d_destroy)(struct sidl__array *);

  /* Clone or addRef depending on whether data is borrowed */
  struct sidl__array *(*d_smartcopy)(struct sidl__array *);

  /* Return the type of the array. */
  int32_t (*d_arraytype)(void);
};

struct sidl__array {
  int32_t                         *d_lower;
  int32_t                         *d_upper;
  int32_t                         *d_stride;
  const struct sidl__array_vtable *d_vtable;
  int32_t                          d_dimen;
  int32_t                          d_refcount;
};


struct sidl_XXXX__array {
  struct sidl__array       d_metadata;
  <value type for XXXX>   *d_firstElement;
};

The string ``$<$value type for XXXX$>$'' should be replaced by something like sidl_boolfor an array of bool, int32_t for any array of int, double for an array of double, int64_t for an array of long, etc. (See Table 5.2)

d_dimen
tells the dimension of the multi-dimensional array. d_lower, d_upper, and d_stride each point to arrays of d_dimen int32_t's. d_lower[i] provides the lower bound for the index in dimension i, and d_upper[i] provides the upper bound for the index in dimension i. Both the lower and upper bounds are valid index values; the upper bound is not one past the end.

d_borrowed
is true if the array does not managed the data that d_firstElement points too, and it is false otherwise. This mainly influences the behavior of the destructor.

Clients should not modify d_lower, d_upper, d_stride, d_dimen, d_borrowed or (in the case of pointers) the values to which they point.

d_stride[i]
determines how elements are packed in dimension i. A value of 1 means that to get from element j to j+1 in dimension i, you add one to the data pointer. Negative values for d_stride can be used to express a transposed matrix. The definition also allows either column or row major ordering for the data, and it also allows treating a subsection of an array as an array.

The data structure was inspired by the data structure used by Numeric Python; although, in Numeric Python, the stride is in terms of bytes. In SIDL, the stride is in terms of number of objects. One can convert to the Numeric Python view of things by multiplying the stride by the sizeof the value type.



babel-1.4.0
users_guide Last Modified 2008-10-16

http://www.llnl.gov/CASC/components
components@llnl.gov