From: Tim Hunter Date: 2007-12-11T08:50:15+09:00 Subject: Re: Zero-copy String Handling Curt Sampson wrote: > On 2007-12-11 02:44 +0900 (Tue), Robert Klemme wrote: > >> This is what I'd do: create a single string per line and use substring >> (aka #[]) to create strings that represent the portion needed; byte >> buffer will be shared then. You don't even need to freeze them because >> of copy on write. > > This was attractive for a couple of seconds, until I realized that not > only does it still add a copy of the entire row of data (albeit as one > large allocation rather than many small ones), but it also doesn't > reduce my object creation load at all. I seem to recall last time I was > playing around with this sort of thing and using a profiler, GC was an > enormous cost for me. This probably isn't surprising given the nature of > the problem; a typical file might be ten million rows of fifty elements > each, which would be 500 million object creations and collections. > > cjs For a problem of this scale, it seems like it would make sense to use a custom class that had some of the methods of String - enough for the callees to treat it like a String - but not in fact String. Give it a .to_s method to convert to a real String when it's really necessary. -- RMagick: http://rmagick.rubyforge.org/