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


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

Re: dataWithBytesNoCopy:length:freeWhenDone

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

Show all headers | View raw


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!

Back to comp.sys.mac.programmer.help | Previous | NextPrevious 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