我错过了什么,或者调用 sendData 我真的需要像这样在堆上创建 3 个 NS 对象吗?或者这甚至是在堆上创建的?反正有没有在堆栈上创建它们?这似乎效率低下!
NSData *data = [NSData dataWithBytes:packet->data length:packet->dataLength];
if(!data)
return -5;
NSString *player = [NSString initWithCString:(char*)peer->data encoding:NSASCIIStringEncoding];
if(!player)
return -6;
NSArray *to = [NSArray arrayWithObject:player];
if(!to)
return -7;
NSError *error;
BOOL success = [[GCHelper sharedInstance].match sendData:data toPlayers:to withDataMode:GKMatchSendDataReliable error:&error];
if (!success) {
printf("Error sending packet %08x %d\n", packet->data, packet->dataLength);
return -8;
}
我可以做这样的事情吗?
NSData data;
[data dataWithBytes:packet->data length:packet->dataLength];
NSString player;
[player initWithCString:(char*)peer->data encoding:NSASCIIStringEncoding];
NSArray to;
[to arrayWithObject:player];
抱歉我的无知,我精通 C++,但对 Objective-C 很陌生。