Is NSData appropriate for large c arrays?
I'm reading large FITS images using the CFITSIO library for C. At first, the actual image/pix开发者_开发问答els are not read in. Only when some sort of operation needs to be done (say, an average of a few images) is the image loaded into memory as a double array. I represent each image as an object of type ImageListing (a custom class). This class knows how to read/write fits files.
To represent a series of images, I use an NSMutableArray inside another class, called ImageStacker. ImageStacker implements methods which can average, subtract, sum the images. Obviously, to do these operations this class needs access to the raw pixels, which it gets by sending the message returnPixelsFrom:(NSInteger)Row
.
My question is, should I:
1) Read in the pixels in the above mentioned method, but read them into a C array (of type double) thats passed by reference.
OR
2) Should I read in the pixels into a local C array, but then compose a NSData object using dataWithBytes:length
and return this object from the method.
What advantage does option 2 have over 1? Keep in mind, that when averaging/adding the pixels I will have to use a C array anyway, so isn't it better to keep using purely C arrays for this purpose?
I think the only reason you'd want to use NSData
is if you needed to hand those bits to a Cocoa class like NSDictionary
that didn't know how to deal with a plain-C array, or wanted to use Cocoa to archive or serialize the data.
If you're generating (or loading) the bits and doing all the work on them in your custom routines, I say leave it in whatever format suits you best, especially if you're just going to stick the data into an NSData
and then pull them right back out. However, there may be something I don't know about NSData
that would make it advantageous to you.
精彩评论