Running out of memory ctfe 16GB
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 7 14:02:33 PDT 2017
Nierjerson wrote:
> How to implement trick is this and are you 100% sure it works?
>
> e.g.,
>
> char[] x;
>
> x.length = 65536;
> x.length = 0;
this won't work. the moment you did `.length = 0;`, you are returned to
point zero.
what you have to do is to maintain "shadow length" yourself, like this:
x.length = 65536;
size_t xpos = 0;
void put (const(char)[] s...) {
foreach (immutable char ch; s) {
if (xpos == x.length) x.length += 65536; // or anything
x[xpos++] = ch;
}
}
More information about the Digitalmars-d
mailing list