Directory recursive walking
dog2002
742617000027 at aaathats3as.com
Fri Jan 15 06:15:06 UTC 2021
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:
>> About 1000 large files.
>>
>> I want to replace several first bytes in all the files, so I
>> just copy the remaining bytes into a new file. Might this be
>> the reason for high memory consumption? If so, is there a way
>> not to copy the entire file, just delete first bytes and write
>> the replaced bytes into the beginning of the file?
>>
>> I use Windows x64.
>
> 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) {}
}
More information about the Digitalmars-d-learn
mailing list