Directory recursive walking
Ferhat Kurtulmuş
aferust at gmail.com
Fri Jan 15 07:31:20 UTC 2021
On Friday, 15 January 2021 at 07:16:21 UTC, Daniel Kozak wrote:
> On Fri, Jan 15, 2021 at 8:00 AM dog2002 via Digitalmars-d-learn
> < digitalmars-d-learn at puremagic.com> 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;
>>
>
> Because of stack overflow
A compiler parameter can be used to increase the maximum stack
size
"dflags": ["-L/STACK:1500000000"]
or recursion can be somehow emulated using heap memory. Here is
my "fake" recursion:
// wins is a range
auto stack = wins.save;
while(!stack.empty){
immutable n = stack.length - 1;
auto window = stack[n];
doSomeThingforEachRecursiveElement(window)
stack.popBack;
if(window.children.length){
foreach (ref child; window.children)
stack.pushBack(child);
}
}
stack.free;
More information about the Digitalmars-d-learn
mailing list