gpt4 book ai didi

c# - 数据完整性问题C#

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:16 25 4
gpt4 key购买 nike

我的问题是下面的 decodedProxyExcerpt2 的分配覆盖了 decodedProxyExcerpt1,我不知道为什么。

有什么线索吗?

提前致谢。

        DecodedProxyExcerpt decodedProxyExcerpt1 = new DecodedProxyExcerpt(stepSize);
if (audiofactory.MoveNext(stepSize))
{
decodedProxyExcerpt1 = audiofactory.Current(stepSize);
}
// At this point decodedProxyExcerpt1.data contains the correct values.

DecodedProxyExcerpt decodedProxyExcerpt2 = new DecodedProxyExcerpt(stepSize);
if (audiofactory.MoveNext(stepSize))
{
decodedProxyExcerpt2 = audiofactory.Current(stepSize);
}
// At this point decodedProxyExcerpt2.data contains the correct values.
// However, decodedProxyExcerpt1.data is overwritten and now holds the values of decodedProxyExcerpt2.data.


public class DecodedProxyExcerpt
{
public short[] data { get; set; } // PCM data

public DecodedProxyExcerpt(int size)
{
this.data = new short[size];
}

}

来自 AudioFactory:

    public bool MoveNext(int stepSize)
{
if (index == -1)
{
index = 0;
return (true);
}
else
{
index = index + stepSize;
if (index >= buffer.Length - stepSize)
return (false);
else
return (true);
}
}

public DecodedProxyExcerpt Current(int stepSize)
{
Array.Copy(buffer, index, CurrentExcerpt.data, 0, stepSize);
return(CurrentExcerpt);
}}

最佳答案

从它的外观来看,audiofactory.MoveNext(stepSize) 保持在相同的引用位置。这导致 audiofactory.Current(stepSize) 停留在同一地址。

因此,decodedProxyExcerpt1decodedProxyExcerpt2 指向相同的引用,因此对其中一个的更改会传播到另一个。

所以,问题出在您的 AudioFactory 类上。

关于c# - 数据完整性问题C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/771891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com