InMemoryRandomAccessMemory can not read right data?

mc 3,221 Reputation points

I want to use StartRecordToStreamAsync to write to stream and then copy the data to another stream.but i find that the stream0's data is different from stream1'data.

var t=stream0.CloneStream();

int bytesRead=t.AsStreamForRead().Read(buffer, 0, buffer.Length)

stream1AsStreamForWrite().Write(buffer, 0, bytesRead)

So I tried and want to find why.

var stream1 = new InMemoryRandomAccessStream();

var stream0 = new InMemoryRandomAccessStream();

var buffer = new byte[510];
for (var i = 0; i < buffer.Length; i++)
    buffer[i] = (byte)i;

stream1.AsStreamForWrite().Write(buffer, 0, buffer.Length);
var buf = new byte[510];
stream1.AsStreamForRead().Read(buf, 0, buf.Length);

stream0.AsStreamForWrite().Write(buf, 0, buf.Length);

var buffer_ = new byte[510];
var buf_ = new byte[510];

stream1.AsStreamForRead().Read(buffer_, 0, buffer.Length);
stream0.AsStreamForRead().Read(buf_, 0, buf.Length);

the two buffer is different why?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
655 questions
{count} votes