我正在使用for循环获取十六进制值和NSDATA的ascii值,因为我创建了一个循环。这适用于文件较小的文件,但是当我在大文件上测试时,它的系统会挂起。原因是挂起这个循环消耗所有内存。我试用这个代码与ARC启用或禁用两者是相同的。我也使用@autoreleasepool {
块,但没有任何变化。这是我的代码
@autoreleasepool {
int indexNo = 0000;
NSMutableString *sbuf = nsData;
NSInteger ivalue = [sbuf length]/48;
NSLog(@"%lu",ivalue);
int j=0;
for (int i = 0; i <= [sbuf length]/48; i++) {
NSString *ch;
NSInteger a =[sbuf length]-j;
// code here
if(a < 48){
ch = [sbuf substringWithRange:NSMakeRange(j,a)];
}
else
{
ch = [sbuf substringWithRange:NSMakeRange(j,48)];
}
NSMutableString * newString = [NSMutableString string];
NSArray * components = [ch componentsSeparatedByString:@" "];
for ( NSString * component in components )
{
int value = 0;
sscanf([component cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
[newString appendFormat:@"%c", (char)value];
// NSLog(@"asckii %c",(char)value);
}
//NSLog(@"hexa demp:%@",ch);
//NSLog(@"ascii Value:%@",newString);
NSString * stringaxcii = [NSString stringWithString: newString];
stringaxcii = [[stringaxcii componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsJoinedByString:@"."];
stringaxcii = [[stringaxcii componentsSeparatedByCharactersInSet:[NSCharacterSet symbolCharacterSet]] componentsJoinedByString:@"."];
stringaxcii = [[stringaxcii componentsSeparatedByCharactersInSet:[NSCharacterSet controlCharacterSet]] componentsJoinedByString:@"."];
stringaxcii = [[stringaxcii componentsSeparatedByCharactersInSet:[NSCharacterSet decomposableCharacterSet]] componentsJoinedByString:@"."];
stringaxcii = [[stringaxcii componentsSeparatedByCharactersInSet:[NSCharacterSet punctuationCharacterSet]] componentsJoinedByString:@"."];
[self.HexaArray addObject:ch];
[self.AsciiValue addObject:stringaxcii];
NSString *hex = [NSString stringWithFormat:@"%08lX",(unsigned long)indexNo];
indexNo = indexNo+16;
[self.IndexArray addObject:hex];
j=j+48;
if (i ==25) {
[self.TableView reloadData];
}
}
[self.TableView reloadData];
}