Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.mac.programmer.help > #61 > unrolled thread
| Started by | "Silver Dream !" <patrycjusz.logiewa@googlemail.com> |
|---|---|
| First post | 2011-10-07 16:26 -0700 |
| Last post | 2011-10-09 05:51 -0700 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.sys.mac.programmer.help
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
| From | "Silver Dream !" <patrycjusz.logiewa@googlemail.com> |
|---|---|
| Date | 2011-10-07 16:26 -0700 |
| Subject | dataWithBytesNoCopy:length:freeWhenDone |
| Message-ID | <b3d9ee72-a379-4769-9ce9-3ffe843144c9@q25g2000vbx.googlegroups.com> |
Hi group! 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. Yet I want all the manipulations done on the bytes of the "small" instances to be reflected in the "large" one. I tried creating the "small" instances using dataWithBytesNoCopy:length:freeWhenDone: but it doesn't seem to work as expected - mutableBytes of the newly created instance point elsewhere than the original mutableBytes. What am I doing wrong? Shouldn't the instance created using dataWithBytesNoCopy:length:freeWhenDone simply hold the same bytes as the originally provided ones? Hoping for some help. Thanks in advance.
[toc] | [next] | [standalone]
| From | William Yeo <wcyeo@shaw.ca> |
|---|---|
| Date | 2011-10-08 13:35 -0700 |
| Message-ID | <wcyeo-D8EF3C.13353808102011@news.giganews.com> |
| In reply to | #61 |
In article <b3d9ee72-a379-4769-9ce9-3ffe843144c9@q25g2000vbx.googlegroups.com>, "Silver Dream !" <patrycjusz.logiewa@googlemail.com> wrote: > Hi group! Hail > 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. NSMutableData is managing an group of bytes, and its real memory use and byte-wise organization is not available to you. It will just copy out bytes and/or copy in bytes through the built-in methods. You are viewing it as a universally addressable array of bytes which will share storage with other (like) objects. It simply won't let you do that. > What am I doing wrong? Shouldn't the instance created using > dataWithBytesNoCopy:length:freeWhenDone simply hold the same bytes as > the originally provided ones? 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.
[toc] | [prev] | [next] | [standalone]
| From | silverdr@srebrnysen.com |
|---|---|
| Date | 2011-10-08 14:28 -0700 |
| Message-ID | <707407.1506.1318109321339.JavaMail.geo-discussion-forums@yqar15> |
| In reply to | #62 |
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.
[toc] | [prev] | [next] | [standalone]
| From | William Yeo <wcyeo@shaw.ca> |
|---|---|
| Date | 2011-10-08 16:40 -0700 |
| Message-ID | <wcyeo-D9850E.16402908102011@news.giganews.com> |
| In reply to | #63 |
In article <707407.1506.1318109321339.JavaMail.geo-discussion-forums@yqar15>, silverdr@srebrnysen.com wrote: Hail > 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.. ? 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.
[toc] | [prev] | [next] | [standalone]
| From | "Silver Dream !" <silverdr@srebrnysen.com> |
|---|---|
| Date | 2011-10-09 05:51 -0700 |
| Message-ID | <16924531.2408.1318164685522.JavaMail.geo-discussion-forums@yqgn17> |
| In reply to | #64 |
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!
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.mac.programmer.help
csiph-web