Data Structure to Data
Data Structure to Data
- Subject: Data Structure to Data
- From: "Bruce Johnson" <email@hidden>
- Date: Thu, 17 Jan 2008 22:28:41 -0800
Hello,I've read that it is not recommended to create an NSData object from a
data structure, especially... "if the structure contains object or pointer
fields, the data object isn't going to archive them correctly"
What about a CFData object?
I have a data structure that contains a pointer field. That which it points
to can vary is size depending on the implementation. Right now I'm doing
this where "data" is my structure that contains custom image data.
unsigned int sizeOfImage = data->xsize * data->ysize * data->channels *
sizeof(unsigned int);
SInt32 sz = (SInt32)(sizeOfImage + sizeof(myImageStruct));
CFDataRef imgData = CFDataCreate(kCFAllocatorDefault, data, sz);
The CFData object is then sent as part of a CFNotification. On the
receiving side of the notification I do this:
myNewImageStruct = (myImageStruct *)CFDataGetBytePtr(imgData);
NSLog(@"%d, %d, %d, %d"
, myNewImageStruct->xsize, myNewImageStruct->ysize,
myNewImageStruct->channels, myNewImageStruct->bitsPerPixel);
The NSLog call works fine but the image data in the pointer field does not
come through (Null data) I'm guessing that it is due what was mentioned
above. Is this correct?
What would be a better way to wrap "myImageStruct" into a CFData object that
I can send as part of a notification.
thanks
----
Bruce Johnson
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden