1. RE: Question for Rob on memory usage
- Posted by Andy Serpa <renegade at earthling.net> May 16, 2002
- 397 views
> > When there are 2 or more pointers to a sequence, > and an element is overwritten, Euphoria will make > a new copy of that sequence, but that does *not* mean > that it will make a copy of the deeper nested data. > Only the top-level of the sequence is copied. > There is no need to copy floating-point numbers > and sequences contained within the main sequence. > > For example, if you sort a sequence of strings, > you'll end up with a different sequence of strings, > but the individual strings are not copied or altered in any way. > The new and old sequences point at the same strings, > but the pointers are in a different order. > So if I understand you correctly, the bottom line is I can do any of that sort of stuff without incurring (i.e. doubling) extra memory usage as long as I never alter the elements themselves? Basically, I'm going to be reading in the contents of text files into a sequence. Each file will equal one element (top-level) of the sequence. But sometimes it will want to load in a file it already has loaded in earlier in the sequence, so I want to be able to just scan the contents of the existing sequence for the filename that is being requested (filename is also stored), and if it is already loaded in, then just append to the sequence that same element again instead of actually loading in the file again and wasting memory...