本文介绍了列表<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 大,所以复制很慢.我可以在不复制的情况下执行此操作吗,例如以某种方式获取指向 List 内部使用的数组的指针?

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<T> 界面并不难做(好吧,只要 Reflector 是免费的并且可以运行,提示提示就行).

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.

这篇关于列表<T>到 T[] 不复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:35