Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!198.186.194.247.MISMATCH!news-out.readnews.com!transit3.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: silverdr@srebrnysen.com Newsgroups: comp.sys.mac.programmer.help Subject: Re: dataWithBytesNoCopy:length:freeWhenDone Date: Sat, 8 Oct 2011 14:28:41 -0700 (PDT) Organization: http://groups.google.com Lines: 44 Message-ID: <707407.1506.1318109321339.JavaMail.geo-discussion-forums@yqar15> References: Reply-To: comp.sys.mac.programmer.help@googlegroups.com NNTP-Posting-Host: 77.8.224.35 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1318109426 18171 127.0.0.1 (8 Oct 2011 21:30:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 8 Oct 2011 21:30:26 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=77.8.224.35; posting-account=aItwoAoAAADl77EHHw0OM7wo4ykKlwDL User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.sys.mac.programmer.help:63 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. >=20 > OK >=20 > > Yet I want all the manipulations > > done on the bytes of the "small" instances to be reflected in the > > "large" one. >=20 > You can't do that because the new NSMutableData is a separate entity, so= =20 > if you change it, it will create a new area for the modified information= =20 > 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" p= art would prevent it from doing this. > If you want all of the changes to be reflected back into the original=20 > string, you'll probably need to create and manage your own data area,=20 > since NSMutableData's purpose in life differs from what you want done. >=20 > If you could elaborate on what you need to do, we might be able to=20 > 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 NSMut= ableData instance) that I need to parse into distinct objects, manipulate t= heir contents separately yet have that content remain part of the original = array of bytes. Something like a file containing document that has its fixe= d 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 vari= ous elements. I hope I make it clear.. ? I probably can extract "mutableBytes" from the original NSMutableData insta= nce, lay C structs over them, manipulate them that way and then create anot= her instance from the bytes to write back to the file. But I perceive this = approach as sort of last resort.