Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.glorb.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: "Silver Dream !" Newsgroups: comp.sys.mac.programmer.help Subject: Re: dataWithBytesNoCopy:length:freeWhenDone Date: Sun, 9 Oct 2011 05:51:25 -0700 (PDT) Organization: http://groups.google.com Lines: 32 Message-ID: <16924531.2408.1318164685522.JavaMail.geo-discussion-forums@yqgn17> References: <707407.1506.1318109321339.JavaMail.geo-discussion-forums@yqar15> 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 X-Trace: posting.google.com 1318165684 21334 127.0.0.1 (9 Oct 2011 13:08:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 9 Oct 2011 13:08:04 +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:65 On Sunday, 9 October 2011 01:40:29 UTC+2, William Yeo wrote: > > 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. > How about if you write an object which: > > a) takes a filepath (eg) at init > b) parses the file contents into an NSArray NSMutableData objects, each > holding one struct, as you suggest > c) has methods to apply changes to structs as needed OR > c) has methods to extract sructs as required > d) has a method to return an NSData with the fully reconstructed byte > string on request > e) has a method to write the reconstruction back to a filepath > > That way you're creating an object which does YOUR work using an NSArray > to maintain the list properly and each component NSMutableData (or you > may only need NSData) is being used properly as well. > > You use your object(s) your way, Cocoa uses its object(s) its way. I think you are right and that seems like a way to go. What I tried to take a shortcut with were the points d, e, and partially b, c. But it seems that I won't escape this. Thank you for your help! -- SD!