Minimize GC memory footprint

Siemargl inqnone at gmail.com
Sat Feb 13 17:54:53 UTC 2021


On Tuesday, 9 February 2021 at 04:05:04 UTC, frame wrote:
> On Saturday, 6 February 2021 at 20:24:00 UTC, frame wrote:
>
>> Hmmm.. with -m64 it's reporting 80 MB used, 203 MB are really 
>> marked as private bytes. Constant. If I use GC.minimize() it 
>> goes up and down and sometimes consumes more than 203 MB. Best 
>> is 100MB. But it doesn't leak endlessly like the 32bit variant.

Hmm, I try to rewrite example in C# and it just hangs in GC, when 
str += "1" added 5 million times.

Then i fix this using StringBuilder, as documented. It works fine.

Next i searched flang forums for D's StringBuilder - found this
https://forum.dlang.org/post/l667ab$cfa$1@digitalmars.com

auto strBuilder = appender!string;
foreach (i; 0 .. 50_000_00) {
    strBuilder.put("a");

And it works too, for 32-bit also =)
Consuming about 100MB RAM.




More information about the Digitalmars-d-learn mailing list