On Fri, Jan 15, 2021 at 8:20 AM dog2002 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote:
> On Friday, 15 January 2021 at 06:56:36 UTC, dog2002 wrote: > > On Friday, 15 January 2021 at 06:33:55 UTC, Paul Backus wrote: > >> On Friday, 15 January 2021 at 06:31:18 UTC, Paul Backus wrote: > >>> > >>> You can save a little bit of memory here by allocating > >>> tempBuffer on the stack: > >>> > >>> ubyte[512] tempBuffer; > >>> _inputFile.rawRead(tempBuffer[]); // note the explicit [] > >> > >> I made a mistake; this should be: > >> > >> ubyte[512] tempArray; > >> ubyte[] tempBuffer = _inputFile.rawRead(tempArray[]); > >> > >> ...with the rest the same as your original version. > > > > Thank you so much! It saves a lot of memory! > > > > And one last question: why the application crashes, if I > > allocate 1 MB array? > > > >>ubyte[1024000] tempBuffer; > > Solved: > > ubyte[] tempBuffer = new ubyte[1024000]; > You can still use ubyte[1024000] tempBuffer; but you have to place it somewhere outside recursion or use a static static ubyte[1024000] tempBuffer;