new_array CArray:Count

CArray:Copy


The Copy method duplicates the current CArray and returns the new object.

Syntax

A = CArray:Copy()

bullet.gif    A is a new CArray containing the same values as the current one. In place of CArray, use the name of the actual object to be copied (see Remarks).

Remarks

This method copies an existing CArray and returns a reference to the new CArray. You cannot copy a CArray or other class object using the trivial statement B = A, as this simply makes the value of B a reference to the object A. In other words, B becomes an alias to A. To get around this, two copy methods are provided by the CArray class:

To create a CArray that is a copy of the current object, use the Copy method. This creates a new CArray B before duplicating the values of the current object A. For example,

 

  B = A:Copy()

-- CArray A already exists

To create a new CArray that is a copy of an existing object, use the copy constructor, as in

 

  B = new_array(A)

-- CArray A already exists

You can use the copying syntax that fits best with your script.

Example

The following script duplicates the CArray A into a new CArray A2:

A = new_array()

-- create a CArray

A:Set( 1, 12.55 )

-- set member 1

A:Set( 40, -155.23 )

-- set member 40

A2 = A:Copy()

-- creates a duplicate CArray A2

Printf("N = %d", A2:Count() )

-- result: N = 2

A:delete()

-- if finished with A, clean up memory

Related Topics

CArray, new


Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.