Re: Unclear on -initWithBytesNoCopy:

2012-03-05 Thread Wade Tregaskis
> I’m not sure I’d want that either, though. If the original string was a > 200-page dissertation and you took a one-word substring from it, it doesn’t > seem reasonable to keep the whole 200-page dissertation all in RAM just to > keep the one-word substring around. But that's a very old probl

Re: Unclear on -initWithBytesNoCopy:

2012-03-05 Thread Charles Srstka
On Mar 5, 2012, at 6:40 PM, Wade Tregaskis wrote: > Perhaps the only 'correct' solution to this problem is to fall back to the > CFString level, where you can pass a custom CFAllocator to e.g. > CFStringCreateWithBytesNoCopy(). That way the lifetime is effectively > managed by the CFString, so

Re: Unclear on -initWithBytesNoCopy:

2012-03-05 Thread Charles Srstka
On Mar 3, 2012, at 3:03 PM, Eli Bach2 wrote: > > On Mar 3, 2012, at 12:15 PM, Jens Alfke wrote: > >> I filed a bug report* saying that this substring optimization shouldn’t be >> used if the source string uses an external buffer, just as it shouldn’t if >> the source string is mutable. They fi

Re: Unclear on -initWithBytesNoCopy:

2012-03-05 Thread Wim Lewis
On 3 Mar 2012, at 12:24 PM, Jens Alfke wrote: > On Mar 3, 2012, at 11:28 AM, Dave Keck wrote: > >> The buffer needs to remain intact until the NSString/NSData object is >> deallocated. > > True; but a strict interpretation of this is that the buffer can _never_ be > destroyed, because you can

Re: Unclear on -initWithBytesNoCopy:

2012-03-05 Thread Wade Tregaskis
Perhaps the only 'correct' solution to this problem is to fall back to the CFString level, where you can pass a custom CFAllocator to e.g. CFStringCreateWithBytesNoCopy(). That way the lifetime is effectively managed by the CFString, so it should behave correctly in all cases. 'course, the imp

Re: Unclear on -initWithBytesNoCopy:

2012-03-03 Thread Eli Bach2
On Mar 3, 2012, at 12:15 PM, Jens Alfke wrote: > I filed a bug report* saying that this substring optimization shouldn’t be > used if the source string uses an external buffer, just as it shouldn’t if > the source string is mutable. They fixed it, but some people there argue that > their origi

Re: Unclear on -initWithBytesNoCopy:

2012-03-03 Thread Jens Alfke
On Mar 3, 2012, at 11:28 AM, Dave Keck wrote: > The buffer needs to remain intact until the NSString/NSData object is > deallocated. True; but a strict interpretation of this is that the buffer can _never_ be destroyed, because you can never predict with 100% accuracy when an object is going

Re: Unclear on -initWithBytesNoCopy:

2012-03-03 Thread Dave Keck
Hit send too soon... > The documentation of -[NSData initWithBytesNoCopy:length:freeWhenDone:] and > of -[NSString initWithBytesNoCopy:length:encoding:freeWhenDone:] is unclear > about the case where freeWhenDone is NO. The data/string object then does not > take ownership of the memory buffer,

Re: Unclear on -initWithBytesNoCopy:

2012-03-03 Thread Dave Keck
> The documentation of -[NSData initWithBytesNoCopy:length:freeWhenDone:] and > of -[NSString initWithBytesNoCopy:length:encoding:freeWhenDone:] is unclear > about the case where freeWhenDone is NO. The data/string object then does not > take ownership of the memory buffer, so the question is: H