To copy the contents of one variable to another, use the IDL_VarCopy() function:

void IDL_VarCopy(IDL_VPTR src, IDL_VPTR dst) 

Arguments src and dst are the source and destination, respectively.

IDL_VarCopy() uses the following rules when copying variables:

  • If the destination variable already has a dynamic part, this dynamic part is released.
  • The destination becomes a copy of the source.
  • If the source is a temporary variable, IDL_VarCopy() does not make a duplicate of the dynamic part for the destination. Instead, the dynamic part of the source is given to the destination, and the source variable itself is returned to the pool of free temporary variables. This is the equivalent of freeing the temporary variable. Therefore, the variable must not be used any further and the caller should not explicitly free the variable. This optimization significantly improves resource utilization and performance because this special case occurs frequently.