本文介绍了TList的快速副本< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有复制通用TList的快速方法吗?

Is there a fast way to copy a generic TList?

  

对于通用的 TList< T> ,可以做到吗?

which uses the knowledge of the internal representation to improve performance. Can it be done?

推荐答案

它根本不可能实现你想要的功能。这是因为复制 T 的内容可能涉及多个简单的内存复制。如果 T 包含任何托管类型(即字符串,接口等),那么这些托管对象的引用计数必须递增。

For the generic TList<T> it is simply not possible to implement the function you want. That's because copy the contents of T may involve more than a simple memory copy. If T contains any managed types (i.e. strings, interfaces etc.) then the reference counts on those managed objects must be incremented.


  • 如果您的 T 确实包含托管类型,那么我怀疑您可以做得比已经拥有的代码好多少。

  • 如果您的 T 不包含任何托管类型,那么内存副本是可行的,但您需要创建自己的类来封装此列表,因为 TList< T> 不合适。

  • If your T does contain managed types then I doubt that you can do much better then the code you already have.
  • If your T does not contain any managed types then a memory copy is viable but you will need to create your own class to encapsulate this list since TList<T> is not appropriate.

这篇关于TList的快速副本&lt; T&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 19:51