The ovm_str_t type

The ovm_str_t type is the OrchIDS type of (fixed-size) character strings.

It is defined this way in src/lang.h:

typedef struct ovm_str_s ovm_str_t;
struct ovm_str_s
{
  gc_header_t gc;
  size_t    len;
  char      str[STR_PAD_LEN];
};

The str field is defined with a dummy length of STR_PAD_LEN; its actual length is given by the len field.

The type ovm_str_t is a type of garbage-collectable data. To allocate a new object of type ovm_str_t, use the function:

ovm_var_t *ovm_str_new(gc_t *gc_ctx, size_t size);

This creates a new ovm_str_t containing size bytes. Calling res the result, one always has TYPE(res)==T_STR. The actual array of bytes is left uninitialized. One can access it using STR(res), and its length (size) is STRLEN(res).

The return type of ovm_str_new() is the universal type ovm_var_t instead of ovm_str_t, for practical reasons.

The result is created white, and much be gc_touch()ed before storing it into a garbage-collectable object.

The returned ovm_str_t object res is modifiable.

There is also a type of virtual character strings ovm_vstr_t.