FROM : Christopher Nebel
DATE : Wed Apr 30 18:04:04 2008
On Apr 30, 2008, at 4:40 AM, Trygve Inda wrote:
>> On 30 Apr 2008, at 12:35, Trygve Inda wrote:
>>
>>> So why the need for + dataWithBytesNoCopy:length:freeWhenDone: ?
>>>
>>> It would seem that if freeWhenDone is YES, these are identical
>>> calls?
>>
>> Because sometimes you might want to use NO. i.e maybe its a non-
>> malloced buffer that you want to treat as NSData, or maybe just a
>> malloced buffer that you need to pass to some method that expects
>> an NSData, but you don't want to have to duplicate the entire buffer.
>
> I guess the freeWhenDone is a newer call then, otherwise it'd make
> more sense to only have the freeWhenDone variant.
-[NSData dataWithBytesNoCopy:length:freeWhenDone] was introduced in
10.2, but it wouldn't necessarily be out of line to have both calls
even if they were the same age. There are lots of methods that are
convenience wrappers for longer methods, such as the the factory
methods on many classes or the -[NSString rangeOfString:] variants.
--Chris Nebel
DATE : Wed Apr 30 18:04:04 2008
On Apr 30, 2008, at 4:40 AM, Trygve Inda wrote:
>> On 30 Apr 2008, at 12:35, Trygve Inda wrote:
>>
>>> So why the need for + dataWithBytesNoCopy:length:freeWhenDone: ?
>>>
>>> It would seem that if freeWhenDone is YES, these are identical
>>> calls?
>>
>> Because sometimes you might want to use NO. i.e maybe its a non-
>> malloced buffer that you want to treat as NSData, or maybe just a
>> malloced buffer that you need to pass to some method that expects
>> an NSData, but you don't want to have to duplicate the entire buffer.
>
> I guess the freeWhenDone is a newer call then, otherwise it'd make
> more sense to only have the freeWhenDone variant.
-[NSData dataWithBytesNoCopy:length:freeWhenDone] was introduced in
10.2, but it wouldn't necessarily be out of line to have both calls
even if they were the same age. There are lots of methods that are
convenience wrappers for longer methods, such as the the factory
methods on many classes or the -[NSString rangeOfString:] variants.
--Chris Nebel
| Related mails | Author | Date |
|---|---|---|
| Allen Dang | Nov 29, 17:55 | |
| Christopher Hickma… | Nov 29, 18:13 | |
| Andreas Monitzer | Nov 29, 19:38 | |
| Allen Dang | Nov 30, 16:41 | |
| David Riggle | Nov 30, 18:46 | |
| Trygve Inda | Apr 30, 11:24 | |
| Luc Heinrich | Apr 30, 11:28 | |
| matt.gough | Apr 30, 12:21 | |
| Trygve Inda | Apr 30, 12:35 | |
| matt.gough | Apr 30, 12:39 | |
| Trygve Inda | Apr 30, 13:40 | |
| Christopher Nebel | Apr 30, 18:04 |






Cocoa mail archive

