如何加快C#中的阵列克隆?

我正在努力解决 Cult of the Bound Variable问题.

您的一部分问题已经为“古代”通用机器实施了解释器.我已经为他们描述的机器执行了一个口译,现在我正在运行大学提供的测试基准程序.

我的C#实现这个解释器很慢!

我在ANTS分析器中启动了我的程序,以查看减速的位置,我可以看到,超过96%的时间被“加载程序”操作所占用.

该操作符的specification如下:

#12. Load Program.

              The array identified by the B register is duplicated
              and the duplicate shall replace the '0' array,regardless of size. The execution finger is placed
              to indicate the platter of this array that is
              described by the offset given in C,where the value
              0 denotes the first platter,1 the second,et
              cetera.

              The '0' array shall be the most sublime choice for
              loading,and shall be handled with the utmost
              veLocity.

这是我的这个操作符的代码

case 12: // Load Program
    _platters[0] = (UInt32[])_platters[(int)_registers[B]].Clone();
    _finger = _registers[C];
    break;

我的整个“通用机器”口译的源代码here.

我能做些什么来做得更快?此解释器还有其他C语言编写,可以更快地完成整个基准测试.

解决方法

您可以尝试使用 Buffer.BlockCopy,但如果在这种情况下产生巨大差异,我会感到惊讶:
case 12: // Load Program
    uint[] src = _platters[(int)_registers[B]];
    _platters[0] = new uint[src.Length];
    Buffer.Blockcopy(src,_platters[0],src.Length * 4);
    _finger = _registers[C];
    break;

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...