Sequence Allocation
- Posted by Michael Nelson <mike-nelson-ODAAT at WORLDNET.ATT.NET> Jul 20, 2000
- 373 views
F Dowling wrote <snip> >Simple, if I define a sequence named "s1": > >s1 = {1,2,3,4,"whatever..."} > >then define another sequence, "s2" > >s2 = {s1,"other stuff"} > > Will s2 contain a copy of s1 as its first element, or a pointer to s1. Carl White responded: <snip> >AFAIK, the answer is the latter; the pointer is copied. This changes it if >you change any of the elements of s1 or s2[1]; A copy must be made at that >time. Carl is entirely correct based on the info in Refman and some posts Rob has made. If a Euphoria object is an integer it is stored as an integer, if a non-integer atom or a sequence, the object actually contains a pointer to the data (though this is transparent to the programmer). Integers and pointers are copied, actual floating point (atom) and sequence data is copied only when necessitated by changes in the data: sequence s1,s2 s1={1,2,3,"xyz"} s2=s1&{4,5,6} --pointers copied, s1's data not copied s2[6]=0 -- no copy of s1's data needed s2[1]=15 -- new copy of s1's data made because of change in data s1[1]=15 -- would have also caused data to be copied In summary, as long as s1 and the part of s2 copied from s1 remain the same, no data is copied, only pointers. -- Mike Nelson