Re: NSMutableData not playing ball
Re: NSMutableData not playing ball
- Subject: Re: NSMutableData not playing ball
- From: Marcel Weiher <email@hidden>
- Date: Thu, 14 Feb 2002 12:18:37 +0100
On Thursday, February 14, 2002, at 03:59 AM, email@hidden wrote:
[wanting to replace 5 bytes inside a NSMutableData with 3 bytes and
moving the rest about]
The documentation for replaceBytesInRange:withBytes: actually asserts
that it can do exactly what you want
No. replaceBytes: does not move data around.
("The receiver is resized to accommodate the new bytes, if necessary."),
This means it will increase the size of the NSMutableData if
range.location + range.length go beyond the current size of the
NSMutableData.
and there is sample code there showing how to do it (turning "Liz and
John" into "Liz and Larry").
This is just an append.
The doc is not explicit about this, but it appears that this method
expects the "withBytes:" parameter to be a malloced block, and asks the
allocator for the size of the block malloced.
No! It simply uses the length of the range parameter for both the
bytes replaced and the number of bytes to replace them with.
This seems rather questionable API design to me,
Not just questionable, downright awful, buggy etc.
as it assumes the pointer passed in is malloced, assumes it knows
which allocator to ask about the block, etc.
So it's a good thing it doesn't do that.
So perhaps the doc is wrong, but it's pretty clear in what it states
the behavior to be. Have you tried using it in the way the doc
suggests?
The doc doesn't suggest anything except that it will add capacity to the
NSMutableData if the new total size doesn't fit.
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.