Iphone 这个循环非常慢,我想是因为我创建了很多中间字符串。我怎样才能加快速度? 我会考虑使用[CODRSTRUTF8St]返回的C字符串并手动解析字符。 > P>我会考虑使用[CODRSTRUTF8St]返回的C字符串并手动解析字符。

Iphone 这个循环非常慢,我想是因为我创建了很多中间字符串。我怎样才能加快速度? 我会考虑使用[CODRSTRUTF8St]返回的C字符串并手动解析字符。 > P>我会考虑使用[CODRSTRUTF8St]返回的C字符串并手动解析字符。,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,考虑: NSArray *splitPoints = [routeGeom componentsSeparatedByString:@"], ["]; routePoints = malloc(sizeof(CLLocationCoordinate2D) * ([splitPoints count] + 1)); int i=0; NSArray *coords; for (NSString* coordStr in splitPoints) { coords = [coordStr

考虑:

NSArray *splitPoints = [routeGeom componentsSeparatedByString:@"], ["];
routePoints = malloc(sizeof(CLLocationCoordinate2D) * ([splitPoints count] + 1));

int i=0;
NSArray *coords; 
for (NSString* coordStr in splitPoints) {

  coords = [coordStr componentsSeparatedByString:@","];

  routePoints[i].latitude = [[[coords objectAtIndex:0] substringFromIndex:1]floatValue];
  routePoints[i].longitude = [[coords objectAtIndex:1] floatValue];

  i++;

}
[coords release];

NSLog(@"** Time to split the route geometry into structs %f", [NSDate timeIntervalSinceReferenceDate] - start);
考虑:

NSArray *splitPoints = [routeGeom componentsSeparatedByString:@"], ["];
routePoints = malloc(sizeof(CLLocationCoordinate2D) * ([splitPoints count] + 1));

int i=0;
NSArray *coords; 
for (NSString* coordStr in splitPoints) {

  coords = [coordStr componentsSeparatedByString:@","];

  routePoints[i].latitude = [[[coords objectAtIndex:0] substringFromIndex:1]floatValue];
  routePoints[i].longitude = [[coords objectAtIndex:1] floatValue];

  i++;

}
[coords release];

NSLog(@"** Time to split the route geometry into structs %f", [NSDate timeIntervalSinceReferenceDate] - start);

在我看来,这似乎是一个NSScanner将获胜的案例-通过字符串和-substringFromIndex分离的组件都将创建堆对象,这是您不希望在紧循环中执行的操作。

在我看来,这就像NSScanner获胜一样-通过String和-substringFromIndex分离的组件都将创建堆对象,这是您不希望在紧循环中执行的操作。

我只是想跳到这里,说您的行[coords release]是不必要的,也是错误的。您应该删除它,以避免在非GC环境中出现问题。您不必发布coords,因为您没有显式地创建或保留它。

我只是想跳到这里,说您的行[coords release]是不必要的,也是错误的。您应该删除它,以避免在非GC环境中出现问题。您不必发布coords,因为您没有显式地创建或保留它。

我想知道有多少用户刚刚遇到了这个叫喊StringBuilder的线程!StringBuilder一直盯着他们的显示器,直到他们看到这是一个C问题。我不知道有多少用户刚刚遇到这个线程,大声喊着StringBuilder!StringBuilder看着他们的监视器,直到他们看到这是一个C问题。