K
kreuters
hey,
can anyone explain to me why this method that is called numerous times
to read chunks of a file works fine with a normal synchronous read,
but causes a large memory leak when BeginRead() is called instead?
private double[] ReadChunk(FileStream fileReader, int
readLength, int channel)
{
short currentShort;
int i;
byte[] inBuffer = new byte[2 * readLength];
double[] scaledChunk = new double[readLength];
// causes massive memory leak, why?
IAsyncResult ar = fileReader.BeginRead(inBuffer, 0,
inBuffer.Length, null, null);
ar.AsyncWaitHandle.WaitOne();
// works fine if i just call this
//fileReader.Read(inBuffer, 0, inBuffer.Length);
for (i = 0; i < scaledChunk.Length; i++)
{
currentShort = (short)((inBuffer[2 * i] << 8) +
inBuffer[2 * i + 1]);
scaledChunk = (scaling[channel, 2] *
(double)currentShort
+ scaling[channel, 1]) * scaling[channel, 3];
}
return scaledChunk;
}
can anyone explain to me why this method that is called numerous times
to read chunks of a file works fine with a normal synchronous read,
but causes a large memory leak when BeginRead() is called instead?
private double[] ReadChunk(FileStream fileReader, int
readLength, int channel)
{
short currentShort;
int i;
byte[] inBuffer = new byte[2 * readLength];
double[] scaledChunk = new double[readLength];
// causes massive memory leak, why?
IAsyncResult ar = fileReader.BeginRead(inBuffer, 0,
inBuffer.Length, null, null);
ar.AsyncWaitHandle.WaitOne();
// works fine if i just call this
//fileReader.Read(inBuffer, 0, inBuffer.Length);
for (i = 0; i < scaledChunk.Length; i++)
{
currentShort = (short)((inBuffer[2 * i] << 8) +
inBuffer[2 * i + 1]);
scaledChunk = (scaling[channel, 2] *
(double)currentShort
+ scaling[channel, 1]) * scaling[channel, 3];
}
return scaledChunk;
}