我正在为XPC服务使用C接口;顺便说一句,我的XPC服务除了以下问题之外运行得非常好。
前几天,我尝试通过XPC发送一个“大”数组,大约有200,000个条目。通常,我的应用程序处理几千个条目的数量级的数据,这是没有问题的。对于其他用途,这种大小的数组可能并不特殊。
下面是用于生成数组的C++服务器代码:
xpc_connection_t remote = xpc_dictionary_get_remote_connection(event);
xpc_object_t reply = xpc_dictionary_create_reply(event);
xpc_object_t times;
times = xpc_array_create(NULL, 0);
for(unsigned int s = 0; s < data.size(); s++)
{
xpc_object_t index = xpc_uint64_create(data[s]);
xpc_array_append_value(times, index);
}
xpc_dictionary_set_value(reply, "times", times);
xpc_connection_send_message(remote, reply);
xpc_release(times);
xpc_release(reply);下面是客户端代码:
xpc_object_t times = xpc_dictionary_get_value(reply, "times");
size_t count = xpc_array_get_count(times);
for(int c = 0; c < count; c++)
{
long my_time = xpc_array_get_uint64(times, c);
local_times.push_back(my_time);
}如果我试图处理一个大的数组,我得到一个seg错误(SIGSEGV)
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libxpc.dylib 0x00007fff90e5cc02 xpc_array_get_count + 0发布于 2016-01-13 15:24:06
当你说“非常大的数组”的时候,你是在说一些启动时可能会被认为是资源抢占和杀戮的东西吗?
XPC实际上只适用于短时间-快速事务运行,而不是基于服务的冗长运行。
如果你要发出让启动等待的调用,那么我建议你试试https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html
当服务死亡的时候..除了SIG_ABORTS之外,是否还有其他特定的事件...被解雇了?
你是否得到"xpc service was invalidated“(这通常意味着launchD终止了它),或者你得到了"xpc service/过早退出”,这通常是处理程序代码错误。
https://stackoverflow.com/questions/27593223
复制相似问题