From: James Edward Gray II Date: 2006-02-04T06:47:06+09:00 Subject: Re: Question about massive API changes On Jan 31, 2006, at 9:06 PM, Sean E. Russell wrote: > On Tuesday 31 January 2006 14:44, mathew wrote: >>> What do you mean by an API facade? >> >> Something that accepts calls via the old API, and translates them >> into >> appropriate calls into the new API. > > I thought that's what you meant. Unfortunately, that's not the API > I'm > talking about. > > In REXML, currently, you can do this: > > el.attributes['someatt'] = "foo" > el.attributes['someatt'] << "bar" > el.attributes['someatt'] == "foobar" # true > > I can do this, because the attributes are being stored as Attribute > objects, > even though you get back String objects from attributes[]. To get > the space > saving, I'm only generating Attribute objects when the user makes > an API call > that returns an Attribute object; otherwise, I store the original > String > objects, which are less than 1/3 the size of an Attribute object. What about using lazy evaluation for the old style methods? The documentation can warn that they are no longer the way, possibly even depreciated, and that memory usage increases dramatically with their usage. Then *if* one of them is called, the needed structures spring into existence and the old API is functional. > Depending on the XML document, this can save a significant amount > of memory. Have you played around at all with storing just offsets into the document? I have no idea if this is remotely practical. It's just a random thought I had. A tag could be four Fixnums perhaps: an open tag start offset, an open tag close offset, a close tag start offset, and a close tag stop offset. How much time does it take to parse one tag knowing all those offsets? The worry is that usage could force you to parse the same tag repeatedly, I guess, but you could potentially get away with never parsing some tags. You could cache the Strings after you parse, for later usage. You might even be able to reasonably leave the document on disk this way (using file seeking). Again, not trying to tell you how to write your library here. Just thinking out loud... James Edward Gray II