c# - 如何从 ReadOnlySpan 获取字节 []不调用 .ToArray?
问题描述
让我们假设类型为 的遗留 API public byte[] ProcessAndCreateNewArray(byte[] readonlyParam);
。如果我有格式输入,var inputReadOnlyParam = new ReadOnlySpan<byte>
那么不做任何其他事情,API 需要像这样调用
// Could the creation of new array by calling .ToArray be avoided?
ReadOnlySpan<byte> res = (ReadOnlySpan<byte>)ProcessAndCreateNewArray(inputReadOnlyParam.ToArray())
但是有什么方法可以避免.ToArray
调用并传入 span 已经拥有的缓冲区?我试图看MemoryMarshal
,但找不到任何东西。这可能吗?
解决方案
推荐阅读
- javascript - 当我使用 ng build 进行部署时,如何解决 Angular 项目中 vendor.js 中的错误语法
- unity3d - 使用行进立方体算法(体素)实现多纹理着色
- android - 如何检查是否为 TTS 下载了语言
- xslt - XSLT/XPath - 计算相邻节点
- java - 如何在 android 中将特定的用户代理与 (Magical) ExoPlayer 一起使用?
- python - 有没有办法使用 Selenium Python 的鼠标滚轮滚动网页?
- python - 如何使用 RecycleGridLayout 在 RecycleView 中使加载的小部件可滚动?
- php - 如何告诉正则表达式不要忽略嵌套匹配?
- java - 为班级绘制自定义?
- c# - 如何使用 db first 方法在实体框架中编写多对多查询?