Share via

InMemoryRandomAccessMemory can not read right data?

mc 7,186 Reputation points
2023-11-17T09:02:33.6533333+00:00

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.Seek(0);
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 development | Windows App SDK

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.