Every frame, the call to NSData
's initWithBytes:length:
causes an 8MB memory allocation & an 8MB copy.
You can get rid of this per-frame allocation/copy by replacing theNSData
object with a persistent NSMutableData
object (set up once at the beginning), and using its mutableBytes
as the destination buffer for the frame's 24- to 32-bit conversion.
(Alternatively, if you prefer to manage the destination-buffer memory yourself, leave the object as NSData
class, but initialize it with initWithBytesNoCopy:length:freeWhenDone:
& pass NO
as the last parameter.)