gpt4 book ai didi

iOS/objective-c(++) 等同于 Windows I/O 完成端口?

转载 作者:行者123 更新时间:2023-11-29 02:43:53 26 4
gpt4 key购买 nike

假设我想实现一个异步加载文件的方法,并以文件内容作为结果返回一些任务。在 .NET 中,我可以说:

public async Task<byte[]> GetFileContentsAsync(string path)
{
using (var fs = File.OpenRead(path))
using (var ms = new MemoryStream())
{
await fs.CopyToAsync(ms);
return ms.ToArray();
}
}

在幕后,CopyToAsync 将利用 IO 完成端口来确保线程不会因空转而浪费在等待 IO 上。

在 Objective-C(++) 中有等效项吗?我可以有效地执行以下合约吗?

ppl::task<StorageBufferPtr> GetFileContentsAsync(const shared_ptr<string> path) 
{
???
}

最佳答案

关于iOS/objective-c(++) 等同于 Windows I/O 完成端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25389912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com