array assignment

Started by kdmoyers, November 06, 2025, 05:22:55 AM

Previous topic - Next topic

kdmoyers

Just checking some things about arrays...

aaa = arrdimension(10,10)
bbb = aaa

In this example, bbb is a pointer to the aaa array, right? it's really the same array storage, just with an alternate variable name.

whereas

ccc = arrayslice(aaa,0,-1,0,-1)

Here ccc becomes a distinct copy of aaa, and can be independently modified, correct?

The mind is everything; What you think, you become.

kdmoyers

those colors came out freaky, here that is again in plain text:

Just checking some things about arrays...

aaa = arrdimension(10,10)
bbb = aaa

In this example, bbb is a pointer to the aaa array, right? it's really the same array storage, just with an alternate variable name.

whereas

ccc = arrayslice(aaa,0,-1,0,-1)

Here ccc becomes a distinct copy of aaa, and can be independently modified, correct?
The mind is everything; What you think, you become.

td

You are correct. Arrays and COM/.Net objects are the only WIL variables that are not deep copied on assignment. WIL uses reference counting for arrays and objects*. The ArraySlice function creates a new array, but uses WIL assignment rules for each element of the new array copied from the old array.

* Object assignment gets a little more complicated. In many cases, WIL allocates new memory to hold the object, but the underlying system object is reference counted.

I know. The above is about as clear as the coffee I am drinking as I type this.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

SMF spam blocked by CleanTalk