Re: Passing sequences to functions & procedures / Memory limits in openEuphoria?
- Posted by mattlewis (admin) Oct 04, 2013
- 2049 views
1) Are sequences passed by reference or by value in functions/procedures?
As a technical matter, they are passed by reference. However, they are reference counted, and a sequence passed as a parameter will have a reference count of at least 2, meaning that any modifications will trigger a copy on write. This means that if you do not intend to modify the sequence, passing even large amounts of data is very cheap.
Of course, this also means that if you're modifying sequence parameters a lot, this can be a significant bottleneck. There are ways around this, and things that can be done to reduce the burden. In std/map.e, for instance, we go to a lot of effort to avoid copy on writes, as they would really drag down map performance.
2) Is there a limit to the size of sequences (apart from the obvious physical limitation; RAM)?
The number of elements in a sequence is tracked by a signed 32-bit integer. Theoretically, a 64-bit machine and euphoria binary could have enough memory to store a sequence with more than 231 elements, but always on a 32-bit implementation, and in most practical cases under 64 bits, you'll run out of memory before you hit that barrier.
Matt