Using closure causes GC allocation
    Vino.B via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Tue Sep  5 21:23:51 PDT 2017
    
    
  
On Monday, 4 September 2017 at 14:42:45 UTC, Azi Hassan wrote:
> On Monday, 4 September 2017 at 05:45:18 UTC, Vino.B wrote:
>>   In order to resolve the issue "Using closure causes GC 
>> allocation" it was stated that we need to use delegates
>
> Alternatively you can drop the functional style and use a 
> foreach loop that doesn't require delegates, but you'd still 
> need the GC to store the result in an array. And even then you 
> could still use Array (from std.container).
Hi All,
  Was able to resolve this issue, thank you for your help, below 
is the changes that i did to resolve the issue.
import std.stdio: File,writeln;
import std.datetime.systime: Clock, days, SysTime;
import std.file: SpanMode, dirEntries, exists, isFile, mkdir, 
remove;
import std.typecons: tuple, Tuple;
import std.algorithm:  filter, map, each;
import std.array: array;
Tuple!(string)[] logClean (string[] Lglst, int LogAge) {
	if (!Lglst[0].exists) { mkdir(Lglst[0]); }
		auto dFiles = dirEntries(Lglst[0], SpanMode.shallow).filter!(a 
=a.exists && a.isFile && a.timeCreated < dtLogAge).map!(a 
=tuple(a.name)).array;
	dFiles.each!(a =a[0].remove);
	return dFiles;
}
SysTime dtLogAge () {
int LogAge = mParams[1];
auto ct2 = Clock.currTime();
auto st2 = ct2 + days(-LogAge);
return st2;
}
void main () {
string[] LogDir = 
["C:\\Users\\admin\\Desktop\\Current\\Script\\D\\Logs"];
logClean(LogDir);
}
"mParams" is another function that reads the value from the 
configuration file and returns the value for the LogAge as 
defined in the configuration file.
From,
Vino.B
    
    
More information about the Digitalmars-d-learn
mailing list