从获取数组列表没有堆分配 [英] Get array from list without heap allocation

查看:145
本文介绍了从获取数组列表没有堆分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名单,我想转让其阵列的属性。

I have a list and I want to assign its array to a property.

public void BuildMesh(List<Vector3> list){
    mesh.vertices=list.ToArray();
}

现在的问题:


  • 该项目是游戏,是在垃圾收集非常艰难这样的ToArray的默认实现()是不是一种选择,因为它创建列表的内部数组旁的新数组。

  • 网格对象是一个封闭源代码API和顶点属性是的Vector3 []所以不能一个指针分配给它。

难道我有什么选项,以防止堆分配

Do I have any option to prevent heap allocation?

编辑:?这不是重复

不能使用的IList<&的Vector3 GT; 。该网是一个封闭源代码API和需要的Vector3 [],所以我不能分配的IList<的Vector3方式>

Can't use IList<Vector3>. The mesh is from a closed source API and needs Vector3[] so I can't assign IList<Vector3> to it.

推荐答案

我觉得你使用统一。如果我是正确的,请尝试 mesh.SetVertices(名单)其中接受列表<的Vector3方式>

I think you're using Unity. If I'm right, try mesh.SetVertices(list) which accept a List<Vector3>.

这篇关于从获取数组列表没有堆分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆