i think the basic problem here is your use of a uint8_t
array. As a C array, you should have a really compelling reason to use it in Objective-C. You don't have a compelling reason, here, and have identified a reason not to use it.
Instead of this:
uint8_t buffer[1024];
Use a NSMutableData
built with dataWithCapacity:
. Something like this:
NSMutableData *data = [NSMutableData dataWithCapacity:1024];
uint8_t *buffer = [data mutableBytes];
You can manipulate the data, then, with methods against data
.
Alternately, you could use memmove
(not memcopy
) to manipulate your array directly. I don't think it's worth it, though; you can generally assume that Foundation will pick a good algorithm, whereas you're likely to pick the simplest, and you're more likely to introduce a block overrun.