Some relevant info I am on OSX using GCD in Objective-C. I have a background task that produces a very large const char *
this is then re-introduced into a new background task. This cycle repeats essentially until the const char*
is empty. Currently I am creating and using NSStrings
in the blocks and then going back to char*
immediately. As you can imagine this does a ton of unnecessary copying of all that.
I am wondering how __block
variables work for non-objects or how I can get away from NSStrings
?
Or
How is memory managed for non-object types?
It is currently just blowing up with ~2 gigs of memory all from the strings.
Here is how it currently looks:
-(void)doSomething:(NSString*)input{
__block NSString* blockCopy = input;
void (^blockTask)(void);
blockTask = ^{
const char* input = [blockCopy UTF8String];
//remainder will point to somewhere along input
const char* remainder = NULL;
myCoolCFunc(input,&remainder);
if(remainder != NULL && remainder[0] != '\0'){
//this is whats killing me the NSString creation of remainder
[self doSomething:@(remainder)];
}
}
/*...create background queue if needed */
dispatch_async(backgroundQueue,blockTask);
}