내 문제는 아래의 decodedProxyExcerpt2 할당이 decodedProxyExcerpt1을 (를) 덮어 쓰고 그 이유를 모르겠다는 것입니다.데이터 무결성 문제 C#
실마리가 있습니까?
미리 감사드립니다. AudioFactory에서
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];
}
}
:
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 내부에있을 수 있습니다. – cjk
audiofactory.Current (stepSize)의 코드를 게시하십시오. 분명히 오류가 있습니다. –
+1에 버그가 있습니다. 7 년 후에 C#이나 .NET에서 데이터 무결성 문제를 상상하기 란 꽤 어렵습니다. CLR 내부 또는 다중 처리 코드에 깊숙이 있습니다. 단순하지만 단일 스레드 코드가 아닙니다. –