Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.mac.programmer.help > #63

Re: dataWithBytesNoCopy:length:freeWhenDone

From silverdr@srebrnysen.com
Newsgroups comp.sys.mac.programmer.help
Subject Re: dataWithBytesNoCopy:length:freeWhenDone
Date 2011-10-08 14:28 -0700
Organization http://groups.google.com
Message-ID <707407.1506.1318109321339.JavaMail.geo-discussion-forums@yqar15> (permalink)
References <b3d9ee72-a379-4769-9ce9-3ffe843144c9@q25g2000vbx.googlegroups.com> <wcyeo-D8EF3C.13353808102011@news.giganews.com>

Show all headers | View raw


On Saturday, 8 October 2011 22:35:39 UTC+2, William Yeo  wrote:

> > I have a question about dealing with binary data. I have a large
> > NSMutableData, which I divide into some logical structure creating
> > another NSMutableData instances, which are supposed to hold a subset
> > of bytes the large instance holds.
> 
> OK
> 
> > Yet I want all the manipulations
> > done on the bytes of the "small" instances to be reflected in the
> > "large" one.
> 
> You can't do that because the new NSMutableData is a separate entity, so 
> if you change it, it will create a new area for the modified information 
> so it will not corrupt the data in any of the other objects.

I see. That's more or less what I am experiencing. I thought the "NoCopy" part would prevent it from doing this.

> If you want all of the changes to be reflected back into the original 
> string, you'll probably need to create and manage your own data area, 
> since NSMutableData's purpose in life differs from what you want done.
> 
> If you could elaborate on what you need to do, we might be able to 
> suggest another mechanism or an alternative.

Basically I need to achieve something similar to lying several structs over an array of unsigned chars in C. I have an array of bytes (held in a NSMutableData instance) that I need to parse into distinct objects, manipulate their contents separately yet have that content remain part of the original array of bytes. Something like a file containing document that has its fixed structure. I need to modify elements of this structure and then write the data back to a file without the need for reconstructing the file from various elements.

I hope I make it clear.. ?

I probably can extract "mutableBytes" from the original NSMutableData instance, lay C structs over them, manipulate them that way and then create another instance from the bytes to write back to the file. But I perceive this approach as sort of last resort.

Back to comp.sys.mac.programmer.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

dataWithBytesNoCopy:length:freeWhenDone "Silver Dream !" <patrycjusz.logiewa@googlemail.com> - 2011-10-07 16:26 -0700
  Re: dataWithBytesNoCopy:length:freeWhenDone William Yeo <wcyeo@shaw.ca> - 2011-10-08 13:35 -0700
    Re: dataWithBytesNoCopy:length:freeWhenDone silverdr@srebrnysen.com - 2011-10-08 14:28 -0700
      Re: dataWithBytesNoCopy:length:freeWhenDone William Yeo <wcyeo@shaw.ca> - 2011-10-08 16:40 -0700
        Re: dataWithBytesNoCopy:length:freeWhenDone "Silver Dream !" <silverdr@srebrnysen.com> - 2011-10-09 05:51 -0700

csiph-web