Value object starts with a ref count of 1 in the array The first put increases the ref count to 2 The delete takes it back to 1 The second put takes it back to 2 At the end of the handler it goes back to 1 since the local var goes away
Thanks, Brian On Jun 25, 2019, 6:35 PM -0400, Mark Wieder via use-livecode <use-livecode@lists.runrev.com>, wrote: > On 6/25/19 1:25 AM, Mark Waddingham via use-livecode wrote: > > On 2019-06-25 04:18, Brian Milby via use-livecode wrote: > > > My guess is that it has to do with the copy on write property of > > > arrays. If you used your method it may force an actual duplication. > > > The existing method just passes a pointer effectively. I could be > > > totally wrong though. > > > > > > On Jun 24, 2019, 10:11 PM -0400, Mark Wieder via use-livecode > > > <use-livecode@lists.runrev.com>, wrote: > > > > > put xArray[item 1 of pPath] into tSubArray > > > > > delete variable xArray[item 1 of pPath] > > > > > put tSubArray into xArray[pKey] > > > > > > > > Interesting. Wouldn't it be faster to do > > > > > > > > put xArray[item 1 of pPath] into xArray[pKey] > > > > delete variable xArray[item 1 of pPath] > > > > > > > > i.e., why the extra copy? > > > > In terms of copies there are none happening in either case - only xArray > > is being mutated - and referencing counting means that the 'puts' are > > all free. > > > > The first will be 'on average' marginally more efficient but that's > > because of the number of keys... > > > > In method (1) the number of keys goes from N -> N - 1 -> N > > > > In method (2) the number of keys goes from N -> N + 1 -> N > > > > Its much more likely that adding a key will cause the engine to have to > > extend the internal vector of key-value pairs it uses to store the array > > mapping then removing a key will cause it to shrink it - also expansion > > is 'on average' slower than shrinking. > > Thanks. That helps. Mostly. > If no copies are made then I'm still a bit weirded out by > > put xArray[item 1 of pPath] into tSubArray > delete variable xArray[item 1 of pPath] > put xArray[item 1 of pPath] into limbo > put tSubArray into xArray[pKey] > > where limbo is empty and tSubArray still retains the contents. > The quantum effect jokes write themselves. > > Is it the case the tSubArray retains a pointer to the contents but the > entry in the hash is otherwise invalidated but not garbage collected > until the reference count goes to zero? > > -- > Mark Wieder > ahsoftw...@gmail.com > > _______________________________________________ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode