On Friday, 15 January 2021 at 06:15:06 UTC, dog2002 wrote:
On Thursday, 14 January 2021 at 22:28:19 UTC, Paul Backus wrote:
On Thursday, 14 January 2021 at 20:23:37 UTC, dog2002 wrote:
[...]
What code are you using to copy the bytes? If you're reading
the whole file into memory at once, that will consume a lot of
memory.
void func(string inputFile, string outFile, uint chunk_size) {
try {
File _inputFile = File(inputFile, "r");
File _outputFile = File(outFile, "w");
ubyte[] tempBuffer = _inputFile.rawRead(new ubyte[](512));
//doing some operations with the tempBuffer
_outputFile.rawWrite(tempBuffer);
_inputFile.seek(tempBuffer.length, SEEK_SET);
foreach(_buffer; _inputFile.byChunk(chunk_size)) {
_outputFile.rawWrite(_buffer);
}
_inputFile.close();
_outputFile.close();
}
catch (Throwable) {}
}
Okay, the reason is incredibly stupid: using WinMain instead of
main causes high memory usage. I don't know why, I use the same
code. If I replace WinMain with main, the memory consumption is
about 6 MB.