Directory recursive walking

Paul Backus snarwin at gmail.com
Fri Jan 15 06:31:18 UTC 2021


On Friday, 15 January 2021 at 06:15:06 UTC, dog2002 wrote:
>
> 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) {}
>
> }

You can save a little bit of memory here by allocating tempBuffer 
on the stack:

     ubyte[512] tempBuffer;
     _inputFile.rawRead(tempBuffer[]); // note the explicit []

     // ...

     _outputFile.rawWrite(tempBuffer[]);

However, those allocations alone shouldn't be enough to get you 
to 4GB+, so the real issue is probably elsewhere.


More information about the Digitalmars-d-learn mailing list