Re: WTF? How can this work?
Re: WTF? How can this work?
- Subject: Re: WTF? How can this work?
- From: Chris Kane <email@hidden>
- Date: Mon, 20 Aug 2001 10:29:14 -0700
On Monday, August 20, 2001, at 02:49 AM, John C. Randolph wrote:
On Sunday, August 19, 2001, at 06:34 PM, Chris Kane wrote:
Mutable collections tend to have "extra slots" allocated to avoid
reallocation on every addition, which kills performance.
I don't suppose you have by any chance, any plans for a fragmentable
array for those occasions where you might have a *lot* of objects in
the array? Or, say, NSReallyBigAndNotNecessarilyContiguousData, for
the future when we have a 64-bit address space?
Well, I suppose we could implement something like that.
<< Chris waves his magic wand, or maybe he wriggles his nose, or maybe
he folds his arms and nods his head ...; there's a pinging sound >>
OK, your copy of Mac OS X 10.0 now does this for large arrays. With
NSArray at least.
NSData is a tougher case, though years ago when we thought about this,
that was where we thought to do it. But the API of NSData promises a
contiguous buffer via the -bytes method. So, you say, we could delay
the continuity until that is requested and concat the buffers at that
point. And, we could, but don't. We ran some tests with existing apps
at the time and found that that the -bytes (or -mutableBytes) were
usually requested fairly quickly after creation, and not usually after
all appending was done. So we decided the extra complexity wasn't worth
it.
NSString does also use the same technique as NSArray, however, and it
finds its way into NSTextStorage backing stores as well. The downside
is that accessing a byte at random in such a structure is O(lg N).
Chris Kane
Cocoa Frameworks, Apple