Regarding hex strings
monarch_dodra
monarchdodra at gmail.com
Sat Oct 20 08:00:44 PDT 2012
On Friday, 19 October 2012 at 03:14:54 UTC, Marco Leise wrote:
>
> Hehe, I assume most of the regulars know this: DMD used to
> use a garbage collector that is disabled. Memory just isn't
> freed! Also it has copy on write semantics during CTFE:
>
> int bug6498(int x)
> {
> int n = 0;
> while (n < x)
> ++n;
> return n;
> }
> static assert(bug6498(10_000_000)==10_000_000);
>
> --> Fails with an 'out of memory' error.
>
> http://d.puremagic.com/issues/show_bug.cgi?id=6498
>
> So, as strange as it sounds, for now try not to write often or
> into large blocks. Using this knowledge I was sometimes able
> to bring down the memory consumption considerably by caching
> recurring concatenations of two strings or to!string calls.
>
> That said, appending single elements to an array may actually
> be better than using a fixed-sized one and have DMD duplicate
> it on every write. :p
>
> Please remember to give Don a cookie when he manages to change
> the compiler to modify in-place where appropriate.
I should have read your post in more detail. I thought you were
saying that allocations are never freed, but it is indeed more
than that: Every write allocates.
I just spent the last hour trying to "optimize" my code, only to
realize that at its "simplest" (Walk the string counting
elements), I run out of memory :/
Can't do much more about it at this point.
More information about the Digitalmars-d
mailing list