清单< T>到T []不复制 [英] List<T> to T[] without copying

查看:103
本文介绍了清单< T>到T []不复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要考虑的OpenGL值类型的大名单。这将是巨大的,如果这可以尽可能快地发生。
我现在做看起来是这样的:

I'm have a large list of value types that needs to be given to OpenGL. It would be great if this could happen as quickly as possible. What I'm doing now looks like this:

List<Vertex> VList = new List<Vertex>();
... //Add vertices
Vertex[] VArray;
VList.CopyTo(VArray, VList.Length);
GL.SetData(..., VArray);

这个名单很容易10MB大,所以复印速度很慢。我能做到这一点不复制,像某种方式得到一个指向数组列表由内部使用?

This list is easily 10MB big, so copying is slow. Can I do this without copying, like somehow get a pointer to the array used internally by List?

或者我要实现我自己的List类。

Or do I have to implement my own List class..

编辑:我忘了提,我不知道会被添加到列表中的元素数

I forgot to mention that I don't know the number of elements that will be added to the List.

推荐答案

借助的IList&LT; T> 接口是不是很难做(当然,不是只要反射是免费的,功能,提示提示)。

The IList<T> interface isn't that difficult to do (well, not so long as Reflector is free and functioning, hint hint).

您可以创建自己的实现,并暴露出内部数组作为一个公共属性。

You can create your own implementation and expose the internal array as a public property.

这篇关于清单&LT; T&GT;到T []不复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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