Re: [NSBitmapImageRep getBitmapDataPlanes] copying data?
Re: [NSBitmapImageRep getBitmapDataPlanes] copying data?
- Subject: Re: [NSBitmapImageRep getBitmapDataPlanes] copying data?
- From: Quincey Morris <email@hidden>
- Date: Mon, 21 Feb 2011 14:27:39 -0800
On Feb 21, 2011, at 13:53, Jonathan Taylor wrote:
> I'm actually doing a fair amount of work with the pixel data, but nevertheless this one copy (specifically the zero fills as well as memcpy) at the start takes considerably longer than the analysis itself.
I recently ran into this problem with zero fills, too. When you let NSBitmapImageRep allocate its own memory, it [apparently] creates a NSData object, and that elaborately zero fills the allocated memory that you're about to overwrite with your own data.
Weirdly, the zero filling took *much* longer than copying pixel data into the NSData buffer afterwards, according to Instruments -- by a factor of something like 35x, IIRC, with a buffer size of about 6MB. I'm guessing that the zeroing was being done as a side-effect of a VM page allocation and that's what was so slow, but it was rather mysterious. (Instruments reported that the time was spent in a function called '__bzero', but again weirdly that didn't seem to be related to 'bzero', which I was using elsewhere in my code. Perhaps.)
My solution was simply to allocate the bitmap memory myself and pass the pointer into the NSBitmapImageRep init. NSAllocateCollectable works fine for this if you're using garbage collection (no further memory management to worry about), but it might be a bit more complicated if you're stuck on retain/release.
On Feb 21, 2011, at 14:02, Ken Thomases wrote:
> NSBitmapImageRep is basically a wrapper around CGImage now. That's what those release notes were saying. So, switching to CGImage probably won't get you anything.
>
> Perhaps Quincey meant to say CIImage, a CoreImage object. That's what the release notes suggest for doing pixel work.
You're giving me too much credit -- I'm not sure what I was trying to say.
OK, what I was *trying* to say is that NSBitmapImageRep in SnowLeopard is basically an immutable object pretending to be mutable. My suggestion was to use a really mutable object instead. I actually don't know if CGImage counts as mutable (in the pixel data sense) or not, because every time I try to use one my application crashes and I go back to NSBitmapImageRep.
I think you're right though -- CIImage is probably the right thing to use. Again, I don't know because every time I try to use one my application crashes and ... ;)
_______________________________________________
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