• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMutableData and Pinned Memory buffers..
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableData and Pinned Memory buffers..


  • Subject: Re: NSMutableData and Pinned Memory buffers..
  • From: Gwynne Raskind <email@hidden>
  • Date: Thu, 13 Dec 2012 19:33:13 -0500

On Dec 13, 2012, at 7:28 PM, Kevin Perry <email@hidden> wrote:
> On Dec 13, 2012, at 4:24 PM, Greg Parker <email@hidden> wrote:
>> On Dec 13, 2012, at 4:13 PM, Robert Monaghan <email@hidden> wrote:
>>> I went ahead and created a really crude subclass of NSMutableData. It seems to work for my situation.
>>> Attached is the code, for posterity. (I am sure I won't be the only one working around this.)
>>>
>>> Any suggestions to make this a bit more "Proper" are welcome.
>> If that's all you need then you should wrap the buffer in an immutable NSData. NSData won't mind if you poke directly at the contents of the buffer.
> Except that he's probably expecting to be able to invoke -mutableBytes and modify the buffer's contents without changing the length. Immutable NSData objects don't respond to -mutableBytes.

In this case, you could do this, as ugly as it is (and it also violates LSP, as it changes the behavior of all NSData objects, though that's unavoidable due to the class cluster anyway; depending on an immutable NSData to throw an exception on receiving -mutableBytes would be so wrong I don't think it's that bad to break it).

@interface NSData (MutableImmutable)
- (void *)mutableBytes;
@end

@implementation NSData (MutableImmutable)
- (void *)mutableBytes {
#if __cplusplus
	return const_cast<void *>(self.bytes);
#else
	return (void *)self.bytes;
#endif
}
@end

-- Gwynne Raskind


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSMutableData and Pinned Memory buffers.. (From: Robert Monaghan <email@hidden>)
 >Re: NSMutableData and Pinned Memory buffers.. (From: Kevin Perry <email@hidden>)
 >Re: NSMutableData and Pinned Memory buffers.. (From: Robert Monaghan <email@hidden>)
 >Re: NSMutableData and Pinned Memory buffers.. (From: Greg Parker <email@hidden>)
 >Re: NSMutableData and Pinned Memory buffers.. (From: Kevin Perry <email@hidden>)

  • Prev by Date: Re: NSMutableData and Pinned Memory buffers..
  • Next by Date: Re: What rect does NSTextFieldCell use to draw its contents?
  • Previous by thread: Re: NSMutableData and Pinned Memory buffers..
  • Next by thread: Re: NSMutableData and Pinned Memory buffers..
  • Index(es):
    • Date
    • Thread