Copy data into a new varying-length structure
The mi_var_copy() function copies data from an existing varying-length structure into a new varying-length structure.
This function performs the following steps:
- Allocates a new varying-length structure.For the new varying-length structure, the mi_var_copy() function allocates a data portion whose size is that of the data in the existing varying-length structure.Server only: The mi_var_copy() function allocates the varying-length structure that it creates with the current memory duration.
- Copies the data in the data portion of the existing varying-length
structure to the data portion of the newly allocated varying-length
structure.
The mi_var_copy() function automatically copies the number of bytes that the data length in the existing varying-length descriptor specifies.
- Returns a pointer to the newly allocated varying-length structure as a pointer to an mi_lvarchar value
Suppose you have the varying-length structure that Figure 1 shows.
The following code fragment uses the mi_var_copy() function
to create a copy of this varying-length structure:
mi_lvarchar *lvarch, *lvarch_copy;
...
lvarch_copy = mi_var_copy(lvarch);
After the call to mi_var_copy() completes successfully,
the lvarch_copy variable points to a new varying-length structure,
as The following figure shows. The varying-length structure that lvarch_copy references
is a completely separate structure from the structure that lvarch references.
Figure 1. Copying a varying-length
structure