我正在从事 ARC 自动转换的项目。
我有一个巨大的文本文件(14MB)的内容存储在一个NSString *_documentDataString
.
现在我有这个循环:
- (void)scanParts
{
NSString *boundary = [boundaryPrefix stringByAppendingString:_header.boundary];
NSMutableArray *parts = [NSMutableArray array];
NSInteger currentLocation = [_documentDataString rangeOfString:boundary].location;
BOOL reachedTheEnd = NO;
while(!reachedTheEnd)
{
NSInteger nextBoundaryLocation = [[_documentDataString substringFromIndex:currentLocation + 1]
rangeOfString:boundary].location;
if(nextBoundaryLocation == NSNotFound)
{
reachedTheEnd = YES;
}
else
{
nextBoundaryLocation += currentLocation + 1;
//[parts addObject:[_documentDataString substringWithRange:
// NSMakeRange(currentLocation, nextBoundaryLocation - currentLocation)]];
currentLocation = nextBoundaryLocation;
}
}
}
但是,我开始收到这些错误:
malloc: *** mmap(size=6496256) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
出了什么问题?
运行此循环时,我什至开始收到此错误:
while(true)
{
NSInteger nextBoundaryLocation = [[_documentDataString substringFromIndex:currentLocation + 1]
rangeOfString:boundary].location;
}