On Friday, 7 April 2017 at 21:02:33 UTC, ketmar wrote:
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;
                }
        }

thanks, I'll try it... seems like it is basically appender though?

Reply via email to